<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Animesh Singh on Medium]]></title>
        <description><![CDATA[Stories by Animesh Singh on Medium]]></description>
        <link>https://medium.com/@itsanimeshsingh?source=rss-5fe50049b001------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*jfPfehvyJP1xX7RJczfBLg.jpeg</url>
            <title>Stories by Animesh Singh on Medium</title>
            <link>https://medium.com/@itsanimeshsingh?source=rss-5fe50049b001------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 05:01:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@itsanimeshsingh/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Understanding @RestController vs @Controller in Spring Boot]]></title>
            <link>https://medium.com/@itsanimeshsingh/understanding-restcontroller-vs-controller-in-spring-boot-1fd9c25fafaf?source=rss-5fe50049b001------2</link>
            <guid isPermaLink="false">https://medium.com/p/1fd9c25fafaf</guid>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring-boot]]></category>
            <dc:creator><![CDATA[Animesh Singh]]></dc:creator>
            <pubDate>Fri, 26 Sep 2025 06:04:10 GMT</pubDate>
            <atom:updated>2025-09-26T06:04:10.670Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>When building applications with Spring Boot, many developers get confused between @Controller and @RestController.</blockquote><blockquote>Both are used to handle HTTP requests, but they serve <strong>different purposes</strong>. In this article, we’ll see the difference with examples — including how to return a <strong>Home page</strong> with @Controller.</blockquote><h3>1️⃣ What is @Controller?</h3><ul><li>@Controller is part of <strong>Spring MVC</strong>.</li><li>It is typically used to return <strong>views (HTML, JSP, Thymeleaf)</strong>.</li><li>The return value is usually a <strong>view name</strong>, not raw data.</li></ul><h3>Example: Serving a Home Page</h3><p>Let’s say we want a <strong>Home page</strong> (home.html) inside src/main/resources/templates.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html xmlns:th=&quot;http://www.thymeleaf.org&quot;&gt;<br>&lt;head&gt;<br>    &lt;title&gt;Home Page&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;h1 th:text=&quot;${message}&quot;&gt;&lt;/h1&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><pre>import org.springframework.stereotype.Controller;<br>import org.springframework.ui.Model;<br>import org.springframework.web.bind.annotation.GetMapping;<br><br>@Controller<br>public class HomeController {<br><br>    @GetMapping(&quot;/home&quot;)<br>    public String home(Model model) {<br>        model.addAttribute(&quot;message&quot;, &quot;Welcome to the Home Page!&quot;);<br>        return &quot;home&quot;; // resolves to home.html in /templates<br>    }<br>}</pre><p>📌 Now, when you visit http://localhost:8080/home, Spring Boot will render the home.html page with your message.</p><h3>2️⃣ What is @RestController?</h3><ul><li>@RestController is a specialized version of @Controller.</li><li>It is a combination of:<br>@Controller<br>@ResponseBody (which means the response is written directly to the body as JSON or text).</li><li>It is used for building <strong>REST APIs</strong>.</li></ul><pre>import org.springframework.web.bind.annotation.GetMapping;<br>import org.springframework.web.bind.annotation.RestController;<br><br>@RestController<br>public class ApiController {<br><br>    @GetMapping(&quot;/api/greet&quot;)<br>    public String greet() {<br>        return &quot;Hello from @RestController!&quot;;<br>    }<br>}</pre><p>📌 When you hit http://localhost:8080/api/greet, you’ll see:</p><pre>Hello from @RestController!</pre><h3>3️⃣ When to Use What?</h3><ul><li>✅ Use <strong>@Controller</strong> when:<br>You’re building <strong>server-side rendered pages</strong> (like JSP, Thymeleaf).<br>Example: Dashboards, Admin panels.</li><li>✅ Use <strong>@RestController</strong> when:<br>You’re building <strong>REST APIs</strong> for frontend clients (React, Angular, Vue) or mobile apps.<br>Example: Authentication APIs, data endpoints.</li></ul><h3>✅ Conclusion</h3><ul><li>@Controller → returns <strong>views (HTML templates)</strong> like a Home page.</li><li>@RestController → returns <strong>data (JSON or text)</strong> for APIs.</li></ul><p>Both are essential in Spring Boot, but choosing the right one depends on whether you’re building <strong>a web page</strong> or <strong>an API</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1fd9c25fafaf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Sending OTP via Email using Spring Boot & Spring Mail]]></title>
            <link>https://medium.com/@itsanimeshsingh/sending-otp-via-email-using-spring-boot-spring-mail-19c84349a15d?source=rss-5fe50049b001------2</link>
            <guid isPermaLink="false">https://medium.com/p/19c84349a15d</guid>
            <category><![CDATA[javamail]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[emailverificationapi]]></category>
            <dc:creator><![CDATA[Animesh Singh]]></dc:creator>
            <pubDate>Fri, 26 Sep 2025 05:37:35 GMT</pubDate>
            <atom:updated>2025-09-26T05:37:35.516Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Email verification is a very common feature in web applications — whether it’s signing up for a new account, resetting a password, or enabling two-factor authentication. In this tutorial, we’ll learn how to send a <strong>One-Time Password (OTP)</strong> to a user’s email using <strong>Spring Boot and Spring Mail</strong>.</blockquote><h3>1️⃣ Add Dependencies</h3><p>Add this dependency in your pom.xml:</p><pre>&lt;dependency&gt;<br>    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>    &lt;artifactId&gt;spring-boot-starter-mail&lt;/artifactId&gt;<br>&lt;/dependency&gt;</pre><h3>2️⃣ Configure Mail Properties</h3><p>In application.properties (or application.yml), configure your SMTP server.<br> (Here I’ll use Gmail SMTP as an example):</p><pre>spring.mail.host=smtp.gmail.com<br>spring.mail.port=587<br>spring.mail.username=your-email@gmail.com<br>spring.mail.password=your-app-password<br>spring.mail.properties.mail.smtp.auth=true<br>spring.mail.properties.mail.smtp.starttls.enable=true</pre><p>👉 <strong>Note:</strong> If you’re using Gmail, you’ll need to generate an <strong>App Password</strong> instead of using your Gmail password.</p><h3>3️⃣ Create an OTP Generator</h3><p>A simple utility to generate numeric OTPs:</p><pre>import java.security.SecureRandom;<br><br>public class OtpUtil {<br>    private static final SecureRandom random = new SecureRandom();<br>    <br>    public static String generateOtp(int length) {<br>        StringBuilder otp = new StringBuilder();<br>        for (int i = 0; i &lt; length; i++) {<br>            otp.append(random.nextInt(10));<br>        }<br>        return otp.toString();<br>    }<br>}</pre><h3>4️⃣ Service to Send Email</h3><p>Now, let’s create a service that will generate the OTP and send it via email.</p><pre>import org.springframework.beans.factory.annotation.Autowired;<br>import org.springframework.mail.SimpleMailMessage;<br>import org.springframework.mail.javamail.JavaMailSender;<br>import org.springframework.stereotype.Service;<br><br>@Service<br>public class EmailService {<br><br>    @Autowired<br>    private JavaMailSender mailSender;<br><br>    public String sendOtpEmail(String toEmail) {<br>        String otp = OtpUtil.generateOtp(6); // 6-digit OTP<br>        <br>        SimpleMailMessage message = new SimpleMailMessage();<br>        message.setTo(toEmail);<br>        message.setSubject(&quot;Your OTP Code&quot;);<br>        message.setText(&quot;Your OTP is: &quot; + otp + &quot;\nIt will expire in 5 minutes.&quot;);<br>        <br>        mailSender.send(message);<br>        <br>        return otp;<br>    }<br>}</pre><p>5️⃣ Create a REST API to Trigger OTP</p><pre>import org.springframework.beans.factory.annotation.Autowired;<br>import org.springframework.web.bind.annotation.*;<br><br>@RestController<br>@RequestMapping(&quot;/api/otp&quot;)<br>public class OtpController {<br><br>    @Autowired<br>    private EmailService emailService;<br><br>    @PostMapping(&quot;/send&quot;)<br>    public String sendOtp(@RequestParam String email) {<br>        String otp = emailService.sendOtpEmail(email);<br>        return &quot;OTP sent to &quot; + email + &quot; (for demo, OTP: &quot; + otp + &quot;)&quot;;<br>    }<br>}</pre><h3>6️⃣ Test the API</h3><ul><li>Start your Spring Boot application</li><li>Use <strong>Postman</strong> or <strong>cURL</strong> to send a request:</li></ul><pre>POST http://localhost:8080/api/otp/send?email=test@example.com</pre><p>You should receive an email with the OTP. 🎉</p><h3>7️⃣ What’s Next?</h3><p>This is a <strong>basic implementation</strong>. In a real application, you should also:</p><ul><li>Store OTPs in DB or cache (e.g., Redis) with expiry</li><li>Verify OTP on another API endpoint</li><li>Limit OTP requests to avoid spam</li></ul><p>We just built a simple OTP email sender with <strong>Spring Boot and Spring Mail</strong>.<br> This feature can be extended for <strong>signup verification</strong>, <strong>password reset</strong>, or <strong>two-factor authentication</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19c84349a15d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>