<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mastering Backend</title>
    <description>The latest articles on DEV Community by Mastering Backend (@masteringbackend).</description>
    <link>https://dev.to/masteringbackend</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F10451%2F2821d44b-ec7b-49c1-9051-514948d5ffe8.png</url>
      <title>DEV Community: Mastering Backend</title>
      <link>https://dev.to/masteringbackend</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/masteringbackend"/>
    <language>en</language>
    <item>
      <title>Don’t Charge Your Users Twice: Understanding Idempotency</title>
      <dc:creator>Jane</dc:creator>
      <pubDate>Tue, 12 May 2026 10:00:30 +0000</pubDate>
      <link>https://dev.to/masteringbackend/dont-charge-your-users-twice-understanding-idempotency-44jb</link>
      <guid>https://dev.to/masteringbackend/dont-charge-your-users-twice-understanding-idempotency-44jb</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw7sxyfzwbyfmfb1df8km.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw7sxyfzwbyfmfb1df8km.png" alt="Don’t Charge Your Users Twice: Understanding Idempotency" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you’ve ever been in a situation where you paid for pizza online, mustered the courage to begin and complete that transaction and accidentally said “you too” in response to “enjoy your meal. It’ll soon arrive” then you know that the only thing worse than the embarrassment from that conversation is realising that the pizza you ordered for say, $20 (great economy) has ensured you get charged $40 or worse $60. You know what’s worse than that still? Now you have to call the same person and complain about being triple-charged.&lt;/p&gt;

&lt;p&gt;You may be amused now as you sit comfortably indoors with your home-cooked meal, but it is an occurrence that may make you lay curses on the poor franchise when, in fact, you may have to shift your blame to the backend developers responsible for the feature.&lt;/p&gt;

&lt;p&gt;Idempotency is an interesting concept. It is based on the fact that acting many times provides the same result as doing it just once. It is important because there are some actions that should not be repeated in a relatively short time, and if done anyway, the developers should assume it to be in error. When building applications, we must prepare for contingencies. You build the backend expecting that maybe a child has the phone and clicked on the “pay for pizza” button twelve times, or an absent-minded mother of eight forgot she paid for her purchase a second ago and clicked the button two more times. Perhaps the WIFI was acting up, so she made another attempt. The point is, without enforcing idempotency for particular endpoints, there would be unimaginable chaos and a lot of pizzas. How does a backend developer avoid such happenings?&lt;/p&gt;

&lt;p&gt;Please note that the examples in this article are based on Node.js and SQL. However, you can still follow along.&lt;/p&gt;

&lt;h3&gt;
  
  
  Where You Find Idempotency
&lt;/h3&gt;

&lt;h4&gt;
  
  
  The GET Route
&lt;/h4&gt;

&lt;p&gt;Certain endpoints enforce idempotency by their very definition. The GET route, for instance, is intuitively idempotent and Safe (meaning, it does not change anything). If you head to a pizza site and request the menu listing, you get the menu listing every time. The result is the same irrespective of how many times the endpoint is called. Whether you click on it 3 times or 30 times, you still get the menu.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get('/pizza-menu', (req, res) =&amp;gt; {
res.json(['Chicken', 'Pepperoni', 'Goat', 'Special?'])
})

// GET requests are idempotent - give the same result no matter how often called
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  The PUT Route
&lt;/h4&gt;

&lt;p&gt;For a PUT request called thrice, that update will occur thrice. If you would rather change your favourite online order, for instance, from “chicken” to “special?” you’d be able to, and if you changed your mind after finding out what “special?” was, you can update as well. However, calling the same request results in the same result, and that makes PUT idempotent though not Safe (meaning that it changes state, but just once when called).&lt;/p&gt;

&lt;p&gt;Here, we’re changing a state of something (your favourite order). If there is a sudden drop in internet connection mid-order and you try again, no harm has occurred because your favourite order remains “special.” We can therefore say that PUT requests are idempotent.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.put('/user/favorite', (req, res) =&amp;gt; {
const { favoritePizza } = req.body
user.favorite = favoritePizza

res.status(200).json({message: `Favorite updated to ${favoritePizza}`})
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  The DELETE Route
&lt;/h4&gt;

&lt;p&gt;The delete route is idempotent, and the reason is quite intuitive. When you delete an order, most well-built apps, at least, don’t give you the option to delete again. However, if, for some inexplicable reason, you find that the button still exists for deleting, perhaps a pizza order, then pushing it again 6 more times does not change the outcome. The result is the same, and you’re not having any pizza. The app will typically report a 404 error, meaning the pizza order no longer exists. The result is the same, hence DELETE requests are idempotent and not Safe (similar to PUT requests).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.delete('/order/:id', (req, res) =&amp;gt; {
deleteOrderFromDb(req.params.id)
res.status(204).json({message: "Order has been successfully deleted"})
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Where You Don’t Find Idempotency
&lt;/h3&gt;

&lt;h4&gt;
  
  
  The POST Route
&lt;/h4&gt;

&lt;p&gt;The POST route is pretty much it for routes that are definitely not idempotent. POST requests allow for creating something, usually by inserting data. This could be an order, money for purchase and so on. If not handled correctly, every request made may repeat an order or a purchase. This is why, as a backend developer who would rather avoid problems, especially with sensitive data, you consider the POST request’s lack of idempotency in your implementations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.post('/orders', (req, res) =&amp;gt; {
const { pizzaId, quantity } = req.body
const newOrder = db.orders.create({ pizzaId, quantity })

res.status(201).json({message: "Order created successfully", data: newOrder})
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This POST request will run as many times as it is called, and that would usually not end well, depending on the use case. Now we know the menace a POST request can be in matters of idempotency, how do we avoid the trouble?&lt;/p&gt;

&lt;h3&gt;
  
  
  Making POST Requests Idempotent
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Unique Indexing
&lt;/h4&gt;

&lt;p&gt;Imagine a particular customer, Fred, likes pizza so much that the day he orders, no one else gets any. You may argue that’s an advantage to the franchise, but maybe the franchise hates this too. As a backend developer working on their online platform, they could decide to place a unique constraint on the  &lt;code&gt;user_id&lt;/code&gt; and  &lt;code&gt;status&lt;/code&gt; fields so that there can only be one active order per user at a time. This is one way to prevent Fred from clicking the order button and creating many orders at once.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE UNIQUE INDEX
idx_one_active_order
ON orders (user_id, status)
WHERE status = 'pending'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Upsert Logic
&lt;/h4&gt;

&lt;p&gt;Another way to ensure a POST request is idempotent is by implementing an upsert strategy. What this means is that if an ID already exists, instead of adding new data to your database, you simply update the existing data with that ID. Picture making pizza orders and consistently pushing the “Add to Cart” button for the same pizza type. Upsert logic does not allow for creating new rows. Instead, it ensures that the count on that particular order is increased. While the first POST request creates the order, subsequent requests just update the quantity of the order.&lt;/p&gt;

&lt;p&gt;This way, you can create logic that does not rush to triple a bill but actually recognises a repeat and does something about it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INSERT INTO orders (id, pizza_id, quantity) 
VALUES ($1, $2, $3)
ON CONFLICT (id) 
DO UPDATE SET quantity = orders.quantity + EXCLUDED.quantity
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Idempotency is an important concept that a backend developer should have in his or her arsenal. It can help to avoid problems where a POST request runs more times than it needs to, leading to complications such as double-billing. You’ve learnt that GET, PUT, and DELETE requests are idempotent while POST requests are not.&lt;/p&gt;

&lt;p&gt;While this article uses pizza orders to explain this concept, a bad handle on idempotency can have far-reaching consequences in finance, business and in several other fields. It’s therefore important to pay close attention to app requirements, so you recognise where to enforce idempotency in your projects.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Have a great one!!!&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Author:  &lt;a href="https://blog.masteringbackend.com/authors/lonercode" rel="noopener noreferrer"&gt;Amanda Ene Adoyi&lt;/a&gt;
&lt;/h3&gt;




&lt;h2&gt;
  
  
  Thank you for being a part of the community
&lt;/h2&gt;

&lt;p&gt;Before you go:&lt;/p&gt;

&lt;h2&gt;
  
  
  Whenever you’re ready
&lt;/h2&gt;

&lt;p&gt;There are 4 ways we can help you become a great backend engineer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://masteringbackend.com/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;The MB Platform:&lt;/strong&gt;&lt;/a&gt;  Join thousands of backend engineers learning backend engineering. Build real-world backend projects, learn from expert-vetted courses and roadmaps, track your learning and set schedules, and solve backend engineering tasks, exercises, and challenges.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://masteringbackend.com/academy?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;The MB Academy:&lt;/strong&gt;&lt;/a&gt;  The “MB Academy” is a 6-month intensive Advanced Backend Engineering Boot Camp to produce great backend engineers.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://backendweeky.dev/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;Join Backend Weekly:&lt;/strong&gt;&lt;/a&gt;  If you like posts like this, you will absolutely enjoy our exclusive weekly newsletter, sharing exclusive backend engineering resources to help you become a great Backend Engineer.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://getbackendjobs.com/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;Get Backend Jobs:&lt;/strong&gt;&lt;/a&gt;  Find over 2,000+ Tailored International Remote Backend Jobs or Reach 50,000+ backend engineers on the #1 Backend Engineering Job Board.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>backenddevelopment</category>
      <category>idempotency</category>
      <category>ai</category>
      <category>backend</category>
    </item>
    <item>
      <title>Mastering @RequestMapping, @RestController, and @Controller in Spring Boot</title>
      <dc:creator>Jane</dc:creator>
      <pubDate>Mon, 11 May 2026 10:00:30 +0000</pubDate>
      <link>https://dev.to/masteringbackend/mastering-requestmapping-restcontroller-and-controller-in-spring-boot-5585</link>
      <guid>https://dev.to/masteringbackend/mastering-requestmapping-restcontroller-and-controller-in-spring-boot-5585</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa1twxgx0lzick2qvpgk0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa1twxgx0lzick2qvpgk0.png" alt="Mastering @RequestMapping, @RestController, and @Controller in Spring Boot" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When building web applications using Spring Boot, three commonly used annotations are  &lt;code&gt;@RequestMapping,&lt;/code&gt;  &lt;code&gt;@RestController,&lt;/code&gt;  and  &lt;code&gt;@Controller.&lt;/code&gt;  These annotations define how your application handles HTTP requests and sends responses back to the client. Understanding them clearly is very important for both real-world development and interviews.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is @Controller?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;@Controller&lt;/code&gt; is used to mark a class as a Spring MVC controller that returns a view (HTML page) as a response.&lt;/p&gt;

&lt;p&gt;This annotation is mainly used in traditional web applications where the server returns a frontend page.&lt;/p&gt;

&lt;h3&gt;
  
  
  Real-world example:
&lt;/h3&gt;

&lt;p&gt;Consider a banking website. When a user logs in, the system verifies the details and then returns a dashboard page. This is handled using a controller.&lt;/p&gt;

&lt;h3&gt;
  
  
  Code example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HomeController {

    @RequestMapping("/home")
    public String homePage() {
        return "home"; // returns home.html
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here,  &lt;code&gt;/home&lt;/code&gt; returns a UI page named  &lt;code&gt;home.html.&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is @RestController?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;@RestController&lt;/code&gt; is a specialized version of  &lt;code&gt;@Controller&lt;/code&gt; that returns data directly in JSON or XML format instead of a view."&lt;/p&gt;

&lt;p&gt;It is widely used in REST APIs where the frontend and backend are separate.&lt;/p&gt;

&lt;h3&gt;
  
  
  Real-world example:
&lt;/h3&gt;

&lt;p&gt;In an e-commerce mobile app, when you open the app and see products, the data comes from backend APIs in JSON format.&lt;/p&gt;

&lt;h3&gt;
  
  
  Code example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;

@RestController
public class UserController {

    @RequestMapping("/user")
    public String getUser() {
        return "User data returned";
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This returns raw data instead of an HTML page.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is @RequestMapping?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;@RequestMapping&lt;/code&gt; is used to map HTTP requests to specific handler methods or classes.&lt;/p&gt;

&lt;p&gt;It connects URLs with the correct method in your application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Real-world example:
&lt;/h3&gt;

&lt;p&gt;A website has multiple pages, like  &lt;code&gt;/login,&lt;/code&gt;  &lt;code&gt;/profile,&lt;/code&gt;  &lt;code&gt;/orders.&lt;/code&gt;  Each URL is mapped to a different method using  &lt;code&gt;@RequestMapping.&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Code example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class ProductController {

    @RequestMapping("/products")
    public String getProducts() {
        return "List of products";
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The final endpoint becomes  &lt;code&gt;/api/products.&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Additional Concepts (Important for Interviews)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Difference between @Controller and @RestController
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;@RestController&lt;/code&gt; =  &lt;code&gt;@Controller&lt;/code&gt; +  &lt;code&gt;@ResponseBody&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This means  &lt;code&gt;@RestController&lt;/code&gt; automatically converts return values into JSON format.&lt;/p&gt;

&lt;p&gt;In  &lt;code&gt;@Controller,&lt;/code&gt;  if you want to return JSON, you must use  &lt;code&gt;@ResponseBody&lt;/code&gt; manually.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Controller
public class DemoController {

    @RequestMapping("/data")
    @ResponseBody
    public String getData() {
        return "Data response";
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. HTTP Method Specific Mapping
&lt;/h3&gt;

&lt;p&gt;Instead of using @RequestMapping everywhere, Spring provides shortcuts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@GetMapping&lt;/code&gt; → for GET requests&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@PostMapping&lt;/code&gt; → for POST requests&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@PutMapping&lt;/code&gt; → for UPDATE&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@DeleteMapping&lt;/code&gt; → for DELETE&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/users")
public class UserApi {

    @GetMapping
    public String getUsers() {
        return "All users";
    }

    @PostMapping
    public String createUser() {
        return "User created";
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Path Variables and Request Parameters
&lt;/h3&gt;

&lt;p&gt;These are commonly asked in interviews.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@GetMapping("/users/{id}")
public String getUserById(@PathVariable int id) {
    return "User id is " + id;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Differences Summary
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@Controller&lt;/code&gt; → Returns HTML view&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@RestController&lt;/code&gt; → Returns JSON/data&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@RequestMapping&lt;/code&gt; → Maps URL to method&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Difference between @Controller and @RestController
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Basic Definition
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;@Controller&lt;/code&gt; is used to return a view (HTML page) from the server.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@RestController&lt;/code&gt; is used to return data (JSON or XML) directly from the server."&lt;/p&gt;

&lt;h4&gt;
  
  
  Main Difference
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;@Controller&lt;/code&gt; -&amp;gt; Used for web applications (returns UI pages)&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@RestController&lt;/code&gt; -&amp;gt; Used for REST APIs (returns data)&lt;/p&gt;

&lt;h4&gt;
  
  
  Real-world Example
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;@Controller:&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Used in websites like banking portals, where a dashboard page is returned after login.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@RestController:&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Used in mobile or frontend applications where backend sends data in JSON format.&lt;/p&gt;

&lt;h4&gt;
  
  
  Code Examples
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;@Controller&lt;/code&gt; Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

@Controller

public class PageController {
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@RequestMapping("/dashboard")
public String dashboard() {
    return "dashboard"; // returns dashboard.html
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@RestController&lt;/code&gt; Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import org.springframework.web.bind.annotation.RestController;

import org.springframework.web.bind.annotation.RequestMapping;

@RestController

public class ApiController {
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@RequestMapping("/data")
public String getData() {
    return "This is API response";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Internal Working
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;@RestController&lt;/code&gt; =  &lt;code&gt;@Controller&lt;/code&gt; +  &lt;code&gt;@ResponseBody&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This means @RestController automatically returns data, while in  &lt;code&gt;@Controller&lt;/code&gt; you need to use  &lt;code&gt;@ResponseBody&lt;/code&gt; manually.&lt;/p&gt;

&lt;h4&gt;
  
  
  When to Use
&lt;/h4&gt;

&lt;p&gt;Use  &lt;code&gt;@Controller&lt;/code&gt; when building frontend-based applications (HTML, JSP, Thymeleaf).&lt;/p&gt;

&lt;p&gt;Use  &lt;code&gt;@RestController&lt;/code&gt; when building backend APIs (used by mobile apps or frontend frameworks like React or Angular).&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;These annotations are the foundation of Spring Boot web development. If you understand when to use @Controller and when to use @RestController, you can design both UI-based and API-based applications easily. @RequestMapping and its variants help you organize your endpoints properly.&lt;/p&gt;

&lt;p&gt;For interviews, always remember the definitions, differences, and real-world usage. Strong basics in these concepts will help you write better code and explain your knowledge clearly.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Have a great one!!!&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Author:  &lt;a href="https://blog.masteringbackend.com/authors/ayush" rel="noopener noreferrer"&gt;Ayush Shrivastava&lt;/a&gt;
&lt;/h3&gt;




&lt;h2&gt;
  
  
  Thank you for being a part of the community
&lt;/h2&gt;

&lt;p&gt;Before you go:&lt;/p&gt;

&lt;h2&gt;
  
  
  Whenever you’re ready
&lt;/h2&gt;

&lt;p&gt;There are 4 ways we can help you become a great backend engineer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://masteringbackend.com/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;The MB Platform:&lt;/strong&gt;&lt;/a&gt;  Join thousands of backend engineers learning backend engineering. Build real-world backend projects, learn from expert-vetted courses and roadmaps, track your learning and set schedules, and solve backend engineering tasks, exercises, and challenges.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://masteringbackend.com/academy?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;The MB Academy:&lt;/strong&gt;&lt;/a&gt;  The “MB Academy” is a 6-month intensive Advanced Backend Engineering Boot Camp to produce great backend engineers.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://backendweeky.dev/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;Join Backend Weekly:&lt;/strong&gt;&lt;/a&gt;  If you like posts like this, you will absolutely enjoy our exclusive weekly newsletter, sharing exclusive backend engineering resources to help you become a great Backend Engineer.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://getbackendjobs.com/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;Get Backend Jobs:&lt;/strong&gt;&lt;/a&gt;  Find over 2,000+ Tailored International Remote Backend Jobs or Reach 50,000+ backend engineers on the #1 Backend Engineering Job Board.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>springboot</category>
      <category>restcontroller</category>
      <category>backenddevelopment</category>
      <category>webapplications</category>
    </item>
    <item>
      <title>Mastering Custom API Response in Java Spring Boot</title>
      <dc:creator>Jane</dc:creator>
      <pubDate>Fri, 08 May 2026 10:00:30 +0000</pubDate>
      <link>https://dev.to/masteringbackend/mastering-custom-api-response-in-java-spring-boot-38oh</link>
      <guid>https://dev.to/masteringbackend/mastering-custom-api-response-in-java-spring-boot-38oh</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fstrapi-images-aws-s3.s3.us-west-2.amazonaws.com%2FNewlatter_image_size_96e7708578.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fstrapi-images-aws-s3.s3.us-west-2.amazonaws.com%2FNewlatter_image_size_96e7708578.png" alt="title"&gt;&lt;/a&gt;&lt;br&gt;
When you start building APIs in Spring Boot, things feel simple at first. You return objects, and Spring automatically converts them into JSON. But as your application grows, problems begin to appear:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Different APIs return different response formats&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Error handling becomes messy&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Frontend developers struggle to handle multiple structures&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Debugging becomes time-consuming&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is where a Custom API Response structure becomes extremely important.&lt;/p&gt;

&lt;p&gt;In this blog, we will deeply understand not just  &lt;em&gt;how&lt;/em&gt;  to implement it, but also  &lt;em&gt;why&lt;/em&gt;  each part exists and how it helps in real-world projects.&lt;/p&gt;
&lt;h2&gt;
  
  
  Problem with Default API Design
&lt;/h2&gt;

&lt;p&gt;Let’s take a real scenario.&lt;/p&gt;
&lt;h3&gt;
  
  
  Case 1: Success API
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Ayush"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Case 2: Error API
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"User not found"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Case 3: Validation Error
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"errors"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"Name is required"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"Email is invalid"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  What Breaks Here
&lt;/h3&gt;

&lt;p&gt;Now the frontend must write logic like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Check if  &lt;code&gt;id&lt;/code&gt; exists → success&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check if  &lt;code&gt;message&lt;/code&gt; exists → error&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check if  &lt;code&gt;errors&lt;/code&gt; exists → validation&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This creates unnecessary conditional handling across web, mobile, and third-party clients.&lt;/p&gt;

&lt;p&gt;As APIs scale, inconsistent contracts increase maintenance costs.&lt;/p&gt;
&lt;h2&gt;
  
  
  Solution: Standard API Response
&lt;/h2&gt;

&lt;p&gt;We fix this by defining a fixed structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"success"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Request successful"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"errors"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"OK"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"timestamp"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2026-04-28T10:00:00"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Each Field Exists
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;data&lt;/strong&gt;  → Holds actual response (can be object, list, or null)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;success&lt;/strong&gt;  → Quick boolean check (frontend friendly)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;message&lt;/strong&gt;  → Human-readable message&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;errors&lt;/strong&gt;  → Detailed error info (useful for debugging)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;status&lt;/strong&gt;  → HTTP status for clarity&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;timestamp&lt;/strong&gt;  → Helps in tracking and debugging issues&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This makes your API predictable and easy to consume.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: StandardResponse Class
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;StandardResponse&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="no"&gt;T&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;success&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;HttpStatus&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;LocalDateTime&lt;/span&gt; &lt;span class="n"&gt;timestamp&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;StandardResponse&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="no"&gt;T&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;success&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
                            &lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;HttpStatus&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;success&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;success&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;errors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;timestamp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;LocalDateTime&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;now&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Deep Explanation
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Generic&lt;/strong&gt; &lt;code&gt;&amp;lt;T&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Makes the class reusable for any data type&lt;/li&gt;
&lt;li&gt;  Example:  &lt;code&gt;String,&lt;/code&gt;  &lt;code&gt;User,&lt;/code&gt;  &lt;code&gt;List&amp;lt;User&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Object errors&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Flexible → can store string, list, or map&lt;/li&gt;
&lt;li&gt;  Useful for validation errors&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;timestamp&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Helps track when API was called&lt;/li&gt;
&lt;li&gt;  Useful in logs and debugging production issues&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;This class becomes the backbone of your API.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: ResponseBuilder (Why It Matters)
&lt;/h2&gt;

&lt;p&gt;Without a builder, you would write this everywhere:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;StandardResponse&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Success"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;HttpStatus&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;OK&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is repetitive and error-prone.&lt;/p&gt;

&lt;h3&gt;
  
  
  Solution:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ResponseBuilder&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;StandardResponse&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;success&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="no"&gt;T&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;StandardResponse&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;HttpStatus&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;OK&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;StandardResponse&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;HttpStatus&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;StandardResponse&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Why This Matters
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Reduces code duplication&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Improves readability&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Central place to modify response logic&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Makes your code cleaner&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Supports cleaner architecture&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 3: Service Layer
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;StandardResponse&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;getUser&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Ayush"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;ResponseBuilder&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;success&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"User fetched successfully"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Why This Is Good Design
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Business logic stays clean&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No HTTP logic here&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Only returns a structured response&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This follows  &lt;strong&gt;Separation of Concerns&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Controller Layer
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@GetMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/user"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;ResponseEntity&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;StandardResponse&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;getUser&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;ResponseEntity&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ok&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;userService&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getUser&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Use ResponseEntity?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Allows control over HTTP status&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Can add headers if needed&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Makes API more flexible&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Even though the response has a status inside, the HTTP status is still important.&lt;/p&gt;

&lt;h2&gt;
  
  
  Global Exception Handling (Very Important)
&lt;/h2&gt;

&lt;p&gt;Instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
   &lt;span class="c1"&gt;// logic&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
   &lt;span class="c1"&gt;// handle&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Use centralized handling:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@RestControllerAdvice&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;GlobalExceptionHandler&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Why?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Centralized error handling&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No repeated try-catch&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cleaner code&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Consistent error response&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 6: Validation Handling (Advanced Understanding)
&lt;/h2&gt;

&lt;p&gt;When using  &lt;code&gt;@Valid,&lt;/code&gt;  Spring throws:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;MethodArgumentNotValidException&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We handle it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;errors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getBindingResult&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getFieldErrors&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;map&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getField&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;": "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getDefaultMessage&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toList&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What This Does
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Extracts all validation errors&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Converts them into readable messages&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Sends them in response&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"errors"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="s2"&gt;"email: must be valid"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="s2"&gt;"name: must not be blank"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7: Real-World Enhancements
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Error Codes
&lt;/h3&gt;

&lt;p&gt;Instead of just a message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"errorCode"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"USER_NOT_FOUND"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Helps frontend and logging systems.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Request ID (Tracing)
&lt;/h3&gt;

&lt;p&gt;In microservices:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"requestId"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"abc-123-xyz"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Helps track requests across services.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Pagination Support
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"page"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"size"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"totalElements"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Important for large datasets.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Execution Time
&lt;/h3&gt;

&lt;p&gt;Track performance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;currentTimeMillis&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Helps optimize slow APIs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Mistakes to Avoid
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Returning raw entities directly&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mixing multiple response formats&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Not handling exceptions globally&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ignoring validation errors&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Hardcoding messages everywhere&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Have a great one!!!&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Author: &lt;a href="https://blog.masteringbackend.com/authors/ayush" rel="noopener noreferrer"&gt;Ayush Shrivastava&lt;/a&gt;
&lt;/h3&gt;




&lt;h3&gt;
  
  
  Thank you for being a part of the community
&lt;/h3&gt;

&lt;p&gt;Before you go:&lt;/p&gt;

&lt;h3&gt;
  
  
  Whenever you’re ready
&lt;/h3&gt;

&lt;p&gt;There are 4 ways we can help you become a great backend engineer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://masteringbackend.com/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;The MB Platform:&lt;/strong&gt;&lt;/a&gt; Join thousands of backend engineers learning backend engineering. Build real-world backend projects, learn from expert-vetted courses and roadmaps, track your learning and set schedules, and solve backend engineering tasks, exercises, and challenges.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://masteringbackend.com/academy?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;The MB Academy:&lt;/strong&gt;&lt;/a&gt; The “MB Academy” is a 6-month intensive Advanced Backend Engineering Boot Camp to produce great backend engineers.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://backendweeky.dev/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;Join Backend Weekly:&lt;/strong&gt;&lt;/a&gt; If you like posts like this, you will absolutely enjoy our exclusive weekly newsletter, sharing exclusive backend engineering resources to help you become a great Backend Engineer.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://getbackendjobs.com/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;Get Backend Jobs:&lt;/strong&gt;&lt;/a&gt; Find over 2,000+ Tailored International Remote Backend Jobs or Reach 50,000+ backend engineers on the #1 Backend Engineering Job Board.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>backenddevelopment</category>
      <category>javadeveloper</category>
      <category>ai</category>
      <category>springboot</category>
    </item>
    <item>
      <title>Why Backend Teams Use Standard API Responses in Spring Boot</title>
      <dc:creator>Jane</dc:creator>
      <pubDate>Thu, 07 May 2026 10:00:30 +0000</pubDate>
      <link>https://dev.to/masteringbackend/why-backend-teams-use-standard-api-responses-in-spring-boot-3n9h</link>
      <guid>https://dev.to/masteringbackend/why-backend-teams-use-standard-api-responses-in-spring-boot-3n9h</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9eaewal74uz4wr7x4pc6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9eaewal74uz4wr7x4pc6.png" alt="title"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Building APIs is not just about returning data. It’s about returning the data in a way that stays clear, predictable, and easy to work with as your system grows.&lt;/p&gt;

&lt;p&gt;Which is why backend teams tend to use standard API responses in Spring Boot. Whenever an endpoint follows a consistent structure, frontend integration becomes smoother, debugging gets faster, and maintenance becomes far less painful.&lt;/p&gt;

&lt;p&gt;This guide breaks down how standard API responses work in Spring Boot and why they matter in real projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Standard API Responses in Spring Boot
&lt;/h2&gt;

&lt;p&gt;Standard API responses in Spring Boot mean returning data in a consistent way across all endpoints. Instead of sending different JSON shapes, the application follows one predictable response structure.&lt;/p&gt;

&lt;p&gt;This is important because APIs are more like contracts, and whenever a response changes randomly between endpoints, frontend apps, mobile clients, and third-party integrations become harder to maintain.&lt;/p&gt;

&lt;p&gt;A standard response includes fields like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;success&lt;/code&gt; – if a request was completed successfully&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;message&lt;/code&gt; – human-readable summary&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;data&lt;/code&gt; – actual payload returned by the API&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;errors&lt;/code&gt; – validation or business errors&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;timestamp&lt;/code&gt; – when a response was generated&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"success"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"User fetched successfully"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;101&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Ada"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"timestamp"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2026-04-29T10:00:00Z"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Example error response:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"success"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Validation failed"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"errors"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"email"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Email is required"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"timestamp"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2026-04-29T10:01:00Z"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This helps to know where to find values without checking every endpoint separately.&lt;/p&gt;

&lt;p&gt;In Spring Boot, standard responses are mostly implemented using DTOs or wrapper classes. Instead of returning raw entities directly from controllers, responses are wrapped in a shared model.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ApiResponse&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;success&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="no"&gt;T&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then a controller can return:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;ResponseEntity&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ok&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ApiResponse&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"User loaded"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;userDto&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Standard responses do not mean every endpoint must return identical payload sizes or force unnecessary wrappers. Lightweight endpoints can stay simple while still following the same contract. The most important thing is structural consistency.&lt;/p&gt;

&lt;p&gt;Spring Boot teams often combine standard responses with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ResponseEntity&lt;/code&gt; for status codes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@ControllerAdvice&lt;/code&gt; for global error handling&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;DTOs for clean payloads&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;validation annotations for input errors&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Try as much as possible to avoid exposing raw database entities, as they often contain internal fields, lazy-loaded relationships, or unstable shapes. DTO-based responses are somewhat safer and clearer.&lt;/p&gt;

&lt;p&gt;When backend teams standardize responses early, APIs become easier to scale, test, document, and consume. That is why consistent API response design is considered a smart long-term practice in Spring Boot applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Standard API Responses Mean in Backend Development
&lt;/h2&gt;

&lt;p&gt;Standard API responses mean your backend returns data using a consistent structure across endpoints. Instead of one route returning raw objects, another returning nested arrays, and another returning plain text, the API follows a predictable format.&lt;/p&gt;

&lt;p&gt;Doesn't matter if the client is a web app, mobile app, internal dashboard, or third-party integration. Predictable responses reduce confusion and speed up development. Consumers know where to find the message, payload, errors, and metadata without reading custom logic for each endpoint.&lt;/p&gt;

&lt;p&gt;A common standard response format includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;success&lt;/code&gt; – indicates request outcome&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;message&lt;/code&gt; – short explanation of the result&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;data&lt;/code&gt; – requested resource or payload&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;errors&lt;/code&gt; – validation or processing issues&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;timestamp&lt;/code&gt; – response time marker&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"success"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Products retrieved successfully"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Keyboard"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Mouse"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Example error response:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"success"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Invalid request"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"errors"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"email"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Email format is invalid"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This does not mean every response should be identical. It means every response should be understandable in the same way.&lt;/p&gt;

&lt;p&gt;In backend development, standard responses solve common problems like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Frontend integration becomes easier*&lt;em&gt;:&lt;/em&gt;* UI teams can build reusable handlers for loading states, success notifications, and error messages.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Testing becomes faster*&lt;em&gt;:&lt;/em&gt;* Automated tests can validate common fields across endpoints.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Documentation becomes clearer: API consumers see repeatable patterns instead of dozens of unrelated response shapes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Debugging improves: Logs and monitoring tools can parse errors consistently.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Standard API responses also work closely with proper HTTP status codes.&lt;/p&gt;

&lt;p&gt;By using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;200 OK&lt;/code&gt; for successful reads&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;201 Created&lt;/code&gt; for new resources&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;400 Bad Request&lt;/code&gt; for validation failures&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;401 Unauthorized&lt;/code&gt; for auth issues&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;404 Not Found&lt;/code&gt; for missing resources&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;500 Internal Server Error&lt;/code&gt; for unexpected failures&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The JSON body gives details while the status code gives protocol meaning.&lt;/p&gt;

&lt;p&gt;Avoid common mistakes like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Returning raw database entities directly&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using different field names for the same concept  &lt;code&gt;(msg,&lt;/code&gt;  &lt;code&gt;message,&lt;/code&gt;  &lt;code&gt;detail)&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Returning  &lt;code&gt;200 OK&lt;/code&gt; for failed operations&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Sending inconsistent error formats&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A strong backend treats response design as part of architecture, not an afterthought. Standard API responses help systems to stay maintainable as teams, features, and integrations grow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Consistent API Response Structure Matters
&lt;/h2&gt;

&lt;p&gt;A consistent API response structure matters a lot because APIs are used repeatedly by humans, applications, and automated systems. If every endpoint responds differently, complexity tends to grow faster.&lt;/p&gt;

&lt;p&gt;When each response follows the same pattern, developers know exactly where to look for data, status messages, errors, and metadata. This saves time during integration and lowers the chance of bugs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"success"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Order retrieved"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;45&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Than a system where one endpoint returns:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"result"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another returns:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"payload"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And another returns:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"responseData"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Frontend development becomes faster when responses are standardized, UI teams can build reusable components for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;success notifications&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;form validation errors&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;loading states&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;pagination handlers&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;empty state messages&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead of rewriting logic for every API route, one pattern can serve many endpoints, and testing becomes simpler.&lt;/p&gt;

&lt;p&gt;Automated tests can verify common fields like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;success&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;message&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;data&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;error structure&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This speeds up regression testing and improves confidence during releases.&lt;/p&gt;

&lt;p&gt;If production issues occur, consistent error payloads help logs, dashboards, and monitoring tools identify problems quickly.&lt;/p&gt;

&lt;p&gt;API docs become easier to read when consumers recognize a repeatable contract. New team members onboard faster because they learn one pattern instead of many.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"success"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Users fetched"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The  &lt;code&gt;data&lt;/code&gt; Content may expand over time, but the outer structure remains familiar.&lt;/p&gt;

&lt;p&gt;Avoid common mistakes like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Mixing naming styles  &lt;code&gt;(snake_case,&lt;/code&gt;  &lt;code&gt;camelCase)&lt;/code&gt;  randomly&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Returning strings for some errors and objects for others&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using success responses with failure messages&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Returning different pagination formats across list endpoints&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A file download endpoint, streaming endpoint, or webhook callback may need different behavior. But for normal JSON APIs, a shared structure creates long-term stability.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Problems Caused by Inconsistent Responses
&lt;/h2&gt;

&lt;p&gt;Inconsistent API responses create confusion fast. The same concept appears under different names, and clients are forced to guess how each endpoint behaves.&lt;/p&gt;

&lt;p&gt;One endpoint returns:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another returns:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"result"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another returns:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"payload"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This breaks predictability, and every new endpoint requires fresh parsing logic.&lt;/p&gt;

&lt;p&gt;UI code becomes harder to maintain. Instead of one reusable handler, multiple condition checks are needed for different response shapes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;checking  &lt;code&gt;data&lt;/code&gt; in one endpoint&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;checking  &lt;code&gt;response&lt;/code&gt; in another&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;checking nested structures somewhere else&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This leads to duplicated logic and more bugs, and having inconsistent error formats can be a major issue.&lt;/p&gt;

&lt;p&gt;One endpoint returns:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Invalid input"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another returns:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"errors"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"email"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Required"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This makes it difficult to build a unified error handling system. Validation messages may not display correctly, and some errors may go unnoticed.&lt;/p&gt;

&lt;p&gt;When something breaks in production, inconsistent responses slow down investigation, and logs become harder to read.&lt;/p&gt;

&lt;p&gt;APIs are expected to behave consistently when responses change unpredictably, and integrations become fragile.&lt;/p&gt;

&lt;p&gt;A small backend change can silently break:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;mobile apps&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;frontend dashboards&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;third-party integrations&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This leads to unexpected failures and harder rollouts.&lt;/p&gt;

&lt;p&gt;API documentation should serve as a guide to users. Inconsistent responses force documentation to include exceptions and special cases for every endpoint.&lt;/p&gt;

&lt;p&gt;Inconsistent API responses do not just affect code readability. They impact performance, reliability, and team productivity. Consistency removes friction and keeps systems manageable as they grow.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Smart Backend Teams Benefit from Standardization
&lt;/h2&gt;

&lt;p&gt;Standardizing API responses gives backend teams a shared contract. Everyone builds against the same structure, which removes ambiguity and speeds up development.&lt;/p&gt;

&lt;p&gt;You spend less time deciding  &lt;em&gt;how&lt;/em&gt;  to return data and more time focusing on business logic. When a standard response format exists, new endpoints follow a known pattern. Instead of designing response structures repeatedly, teams reuse:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;a common response wrapper&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;consistent error formats&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;shared status handling&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This reduces decision fatigue and speeds up delivery.&lt;/p&gt;

&lt;p&gt;APIs change over time. Standard responses make these changes easier to manage.&lt;/p&gt;

&lt;p&gt;You can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;keep the outer response structure stable&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;evolve the inner  &lt;code&gt;data&lt;/code&gt; payload&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;avoid breaking existing clients&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This leads to smoother upgrades and fewer disruptions.&lt;/p&gt;

&lt;p&gt;Smart backend teams treat API response design as part of system architecture. Standardization is not just about consistency it directly impacts speed, reliability, and long-term maintainability.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Have a great one!!!&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Author: &lt;a href="https://blog.masteringbackend.com/authors/Toluwanimi" rel="noopener noreferrer"&gt;Toluwanimi Fawole&lt;/a&gt;
&lt;/h3&gt;




&lt;h3&gt;
  
  
  Thank you for being a part of the community
&lt;/h3&gt;

&lt;p&gt;Before you go:&lt;/p&gt;

&lt;h3&gt;
  
  
  Whenever you’re ready
&lt;/h3&gt;

&lt;p&gt;There are 4 ways we can help you become a great backend engineer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://masteringbackend.com/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;The MB Platform:&lt;/strong&gt;&lt;/a&gt; Join thousands of backend engineers learning backend engineering. Build real-world backend projects, learn from expert-vetted courses and roadmaps, track your learning and set schedules, and solve backend engineering tasks, exercises, and challenges.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://masteringbackend.com/academy?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;The MB Academy:&lt;/strong&gt;&lt;/a&gt; The “MB Academy” is a 6-month intensive Advanced Backend Engineering Boot Camp to produce great backend engineers.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://backendweeky.dev/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;Join Backend Weekly:&lt;/strong&gt;&lt;/a&gt; If you like posts like this, you will absolutely enjoy our exclusive weekly newsletter, sharing exclusive backend engineering resources to help you become a great Backend Engineer.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://getbackendjobs.com/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;Get Backend Jobs:&lt;/strong&gt;&lt;/a&gt; Find over 2,000+ Tailored International Remote Backend Jobs or Reach 50,000+ backend engineers on the #1 Backend Engineering Job Board.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>backenddevelopment</category>
      <category>api</category>
      <category>ai</category>
      <category>springboot</category>
    </item>
    <item>
      <title>How to Become an AI Engineer from a Java Developer Using Spring AI</title>
      <dc:creator>Jane</dc:creator>
      <pubDate>Wed, 06 May 2026 10:00:30 +0000</pubDate>
      <link>https://dev.to/masteringbackend/how-to-become-an-ai-engineer-from-a-java-developer-using-spring-ai-3go7</link>
      <guid>https://dev.to/masteringbackend/how-to-become-an-ai-engineer-from-a-java-developer-using-spring-ai-3go7</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fstrapi-images-aws-s3.s3.us-west-2.amazonaws.com%2FNewlatter_image_size_1_46a709ef2b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fstrapi-images-aws-s3.s3.us-west-2.amazonaws.com%2FNewlatter_image_size_1_46a709ef2b.png" alt="title" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
The world is quickly moving towards Artificial Intelligence, and many Java developers are now thinking about how they can transition into AI engineering. The good news is you don’t need to start from scratch. If you already know Java and Spring Boot, you already have a strong foundation. With tools like Spring AI, the journey becomes much easier and practical.&lt;/p&gt;

&lt;p&gt;Let’s understand this step by step in a simple and realistic way.&lt;/p&gt;

&lt;h3&gt;
  
  
  Start with the Right Mindset
&lt;/h3&gt;

&lt;p&gt;Before jumping into tools and code, you need to understand one thing: AI engineering is not only about machine learning models. It is also about building real-world applications that use AI.&lt;/p&gt;

&lt;p&gt;As a Java developer, you already know how to build scalable systems, APIs, and backend logic. Now you just need to learn how to integrate AI into those systems.&lt;/p&gt;

&lt;p&gt;Think like this:&lt;/p&gt;

&lt;p&gt;Earlier → You were building APIs&lt;/p&gt;

&lt;p&gt;Now → You will build intelligent APIs&lt;/p&gt;

&lt;h3&gt;
  
  
  Learn Basic AI Concepts (No Deep Math Required)
&lt;/h3&gt;

&lt;p&gt;You don’t need to become a data scientist. Just focus on understanding:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is AI and Machine Learning&lt;/li&gt;
&lt;li&gt;What is a Large Language Model (LLM)&lt;/li&gt;
&lt;li&gt;What is Prompt Engineering&lt;/li&gt;
&lt;li&gt;Basics of embeddings and vector databases&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;

&lt;p&gt;If a user asks, “Suggest me a good laptop under 50k,” an AI system can understand the intent and generate a helpful answer. You don’t need to train the model; you just need to use it correctly.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understand How APIs Work with AI
&lt;/h3&gt;

&lt;p&gt;Most modern AI systems, like GPT models, are accessed using APIs. This is where your Java experience helps a lot.&lt;/p&gt;

&lt;p&gt;You already know:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;REST APIs&lt;/li&gt;
&lt;li&gt;JSON handling&lt;/li&gt;
&lt;li&gt;HTTP calls&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now you just need to call AI APIs and process responses.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;

&lt;p&gt;Imagine you are building a customer support system. Instead of writing static responses, you can call an AI API to generate dynamic replies based on user queries.&lt;/p&gt;

&lt;h3&gt;
  
  
  Learn Spring AI
&lt;/h3&gt;

&lt;p&gt;Spring AI is designed to make AI integration easy for Java developers. It works just like Spring Boot, so you will feel comfortable.&lt;/p&gt;

&lt;p&gt;With Spring AI, you can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Connect to AI models (like OpenAI)&lt;/li&gt;
&lt;li&gt;Build chat-based applications&lt;/li&gt;
&lt;li&gt;Handle prompts easily&lt;/li&gt;
&lt;li&gt;Integrate embeddings and vector search&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;

&lt;p&gt;You can build a chatbot in your existing Spring Boot app that answers user questions about your product.&lt;/p&gt;

&lt;p&gt;Simple use case:&lt;/p&gt;

&lt;p&gt;A user types: “How do I reset my password?”&lt;/p&gt;

&lt;p&gt;Your system sends this query to an AI model using Spring AI and returns a clean, human-like response.&lt;/p&gt;

&lt;h3&gt;
  
  
  Build Small Projects (Very Important)
&lt;/h3&gt;

&lt;p&gt;Learning the theory aspect is not enough. You must build real applications.&lt;/p&gt;

&lt;p&gt;Start with simple projects like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AI Chatbot for FAQs&lt;/li&gt;
&lt;li&gt;Resume Analyzer using AI&lt;/li&gt;
&lt;li&gt;Email reply generator&lt;/li&gt;
&lt;li&gt;Blog writing assistant&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;

&lt;p&gt;Supposing you’re running an e-commerce platform. You can build an AI feature where users ask:&lt;/p&gt;

&lt;p&gt;“Suggest me shoes for running under ₹3000.”&lt;/p&gt;

&lt;p&gt;And your system generates smart recommendations.&lt;/p&gt;

&lt;p&gt;This is exactly what companies are doing today.&lt;/p&gt;

&lt;h3&gt;
  
  
  Learn Prompt Engineering
&lt;/h3&gt;

&lt;p&gt;Prompt engineering means writing better inputs to get better outputs from AI.&lt;/p&gt;

&lt;p&gt;Bad prompt:&lt;/p&gt;

&lt;p&gt;“Tell me about Java.”&lt;/p&gt;

&lt;p&gt;Good prompt:&lt;/p&gt;

&lt;p&gt;“Explain Java in simple terms for beginners with real-world examples in 100 words.”&lt;/p&gt;

&lt;p&gt;You will see a huge difference in output quality. As a Java developer, think of prompts like function inputs. Better input = better output.&lt;/p&gt;

&lt;h3&gt;
  
  
  Work with Data (Basic Level)
&lt;/h3&gt;

&lt;p&gt;You don’t need deep data science knowledge, but you should know:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to store and retrieve data&lt;/li&gt;
&lt;li&gt;How to use vector databases&lt;/li&gt;
&lt;li&gt;How embeddings work&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;

&lt;p&gt;If you build a document search system, you can store documents as embeddings and allow users to search using natural language.&lt;/p&gt;

&lt;p&gt;User asks:&lt;/p&gt;

&lt;p&gt;“Show me policies related to refunds.”&lt;/p&gt;

&lt;p&gt;AI finds the most relevant content even if exact words don’t match.&lt;/p&gt;

&lt;h3&gt;
  
  
  Combine AI with Your Existing Skills
&lt;/h3&gt;

&lt;p&gt;This is your biggest advantage.&lt;/p&gt;

&lt;p&gt;You already know:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Spring Boot&lt;/li&gt;
&lt;li&gt;Microservices&lt;/li&gt;
&lt;li&gt;Security&lt;/li&gt;
&lt;li&gt;Database handling&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now combine them with AI.&lt;/p&gt;

&lt;p&gt;Example: In a banking app:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use AI to detect fraud patterns&lt;/li&gt;
&lt;li&gt;Generate automated customer responses&lt;/li&gt;
&lt;li&gt;Summarize transaction history&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You are not replacing your skills; you’re simply upgrading them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Learn by Building Real Use Cases
&lt;/h3&gt;

&lt;p&gt;Companies don’t hire AI engineers just for knowledge; they want problem solvers who focus on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Solving real business problems&lt;/li&gt;
&lt;li&gt;Building usable features&lt;/li&gt;
&lt;li&gt;Creating end-to-end applications&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;

&lt;p&gt;Instead of just saying “I know AI,” build a project like:&lt;/p&gt;

&lt;p&gt;“AI-powered ticket resolution system using Spring AI”&lt;/p&gt;

&lt;p&gt;That’s what makes you stand out.&lt;/p&gt;

&lt;h3&gt;
  
  
  Keep It Simple and Consistent
&lt;/h3&gt;

&lt;p&gt;Don’t try to learn everything at once.&lt;/p&gt;

&lt;p&gt;Follow this path by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Learning the basics of AI&lt;/li&gt;
&lt;li&gt;Understanding APIs&lt;/li&gt;
&lt;li&gt;Using Spring AI&lt;/li&gt;
&lt;li&gt;Building projects&lt;/li&gt;
&lt;li&gt;Improving step by step&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Consistency matters more than speed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Getting Started with Spring AI: A Simple Guide for Java Developers
&lt;/h3&gt;

&lt;p&gt;Artificial Intelligence is becoming an important part of modern applications, but integrating AI into backend systems can feel complex. Different AI providers have different APIs, formats, and configurations, which makes development harder. This is where Spring AI helps Java developers.&lt;/p&gt;

&lt;p&gt;Spring AI is a project from the Spring ecosystem that makes it easy to integrate AI into Java applications. It follows the same philosophy as Spring Boot. Instead of worrying about multiple AI APIs, Spring AI provides a consistent way to work with them. ( &lt;a href="https://codefarm0.medium.com/getting-started-with-spring-ai-a-comprehensive-guide-for-beginners-34013e8d4a39?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;Medium&lt;/a&gt;)&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Spring AI?
&lt;/h3&gt;

&lt;p&gt;Spring AI is an extension of the Spring Framework designed to simplify working with AI models like chat models, embeddings, and image generation tools. It provides abstraction layers so that you don’t need to handle provider-specific complexity. ( &lt;a href="https://codefarm0.medium.com/getting-started-with-spring-ai-a-comprehensive-guide-for-beginners-34013e8d4a39?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;Medium&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;It allows you to connect your Java application with AI models easily, just like you connect a database using Spring.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Spring AI is Important
&lt;/h3&gt;

&lt;p&gt;Before Spring AI, developers had to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Write custom code for each AI provider&lt;/li&gt;
&lt;li&gt;Handle different API formats&lt;/li&gt;
&lt;li&gt;Manage complex integrations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Spring AI solves this by giving a unified API layer. You can switch between providers like OpenAI or others without changing much code. ( &lt;a href="https://spring.io/projects/spring-ai?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;Home&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;It also focuses on connecting your business data and APIs with AI models, which is the real need in modern applications. ( &lt;a href="https://docs.spring.io/spring-ai/reference/?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;Home&lt;/a&gt;)&lt;/p&gt;

&lt;h3&gt;
  
  
  Core Components of Spring AI
&lt;/h3&gt;

&lt;p&gt;Spring AI provides several important components that make development easy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ChatClient: Which is used to build chatbots or conversational features&lt;/li&gt;
&lt;li&gt;EmbeddingClient: Helps to convert text into vectors for search and recommendations&lt;/li&gt;
&lt;li&gt;VectorStore: Stores embeddings for semantic search&lt;/li&gt;
&lt;li&gt;PromptTemplate: Helps create dynamic and reusable prompts&lt;/li&gt;
&lt;li&gt;Function Calling: Allows AI to call Java methods directly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These components provide a consistent programming model, regardless of which AI provider you use.&lt;/p&gt;

&lt;h3&gt;
  
  
  How Spring AI Works (Simple Flow)
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;User sends a request (Example: “Explain Java basics”)&lt;/li&gt;
&lt;li&gt;Spring Boot controller receives the request&lt;/li&gt;
&lt;li&gt;Spring AI processes it using prompts&lt;/li&gt;
&lt;li&gt;It calls an AI model (like OpenAI)&lt;/li&gt;
&lt;li&gt;The response is returned to the user&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This flow is very similar to how you already build REST APIs, which makes it easy for Java developers to adopt.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to Get Started
&lt;/h3&gt;

&lt;p&gt;Starting with Spring AI is simple if you already know Spring Boot.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Create a Spring Boot project
&lt;/h3&gt;

&lt;p&gt;Go to Spring Initializr and add dependencies for Spring AI.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Add dependencies
&lt;/h3&gt;

&lt;p&gt;You can add Spring AI dependencies using Maven or Gradle. It is available in Maven Central, so setup is straightforward.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Configure API keys
&lt;/h3&gt;

&lt;p&gt;Add your AI provider API key (like OpenAI) in &lt;a href="http://application.properties" rel="noopener noreferrer"&gt;application.properties&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Write a simple AI service
&lt;/h3&gt;

&lt;p&gt;Use ChatClient to send prompts and get responses.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;

&lt;p&gt;Create an endpoint like:&lt;/p&gt;

&lt;p&gt;GET /ask?question=What is Spring Boot?&lt;/p&gt;

&lt;p&gt;Your backend will send this to an AI model and return a clean response.&lt;/p&gt;

&lt;h3&gt;
  
  
  Real-World Use Cases
&lt;/h3&gt;

&lt;p&gt;Spring AI is not just for demos. It is used in real applications:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Customer Support Chatbots&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Automate responses for user queries in applications.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Document Q&amp;amp;A Systems&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Users can ask questions about company policies or documents.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Smart Search Systems&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Instead of keyword search, users can search in natural language.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Content Generation&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Generate emails, reports, or product descriptions automatically.&lt;/p&gt;

&lt;p&gt;An e-commerce app can use Spring AI to suggest products because the system understands intent and gives smart recommendations.&lt;/p&gt;

&lt;h3&gt;
  
  
  Advanced Features
&lt;/h3&gt;

&lt;p&gt;Spring AI also supports advanced capabilities like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Retrieval Augmented Generation (RAG) for using your own data&lt;/li&gt;
&lt;li&gt;Chat memory for conversation-based apps&lt;/li&gt;
&lt;li&gt;Multi-model support (text, image, audio)&lt;/li&gt;
&lt;li&gt;Tool calling for executing backend logic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These features help build production-level AI systems, not just simple demos. ( &lt;a href="https://spring.io/ai?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;Home&lt;/a&gt;)&lt;/p&gt;

&lt;h3&gt;
  
  
  Final Thoughts
&lt;/h3&gt;

&lt;p&gt;Spring AI makes AI development simple for Java developers by removing unnecessary complexity. If you already know Spring Boot, you can start building AI-powered applications without learning a completely new ecosystem, and instead of switching to Python or learning heavy machine learning concepts, you can stay in Java and still build powerful AI features.&lt;/p&gt;

&lt;p&gt;Start small, build a chatbot or a smart API, and then slowly move towards advanced use cases. That’s the best way to grow in AI with Spring AI.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Have a great one!!!&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Author: &lt;a href="https://blog.masteringbackend.com/authors/ayush" rel="noopener noreferrer"&gt;Ayush Shrivastava&lt;/a&gt;
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Thank you for being a part of the community
&lt;/h3&gt;




&lt;p&gt;Before you go:&lt;/p&gt;

&lt;h3&gt;
  
  
  Whenever you’re ready
&lt;/h3&gt;

&lt;p&gt;There are 4 ways we can help you become a great backend engineer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://masteringbackend.com/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;The MB Platform:&lt;/strong&gt;&lt;/a&gt; Join thousands of backend engineers learning backend engineering. Build real-world backend projects, learn from expert-vetted courses and roadmaps, track your learning and set schedules, and solve backend engineering tasks, exercises, and challenges.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://masteringbackend.com/academy?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;The MB Academy:&lt;/strong&gt;&lt;/a&gt; The “MB Academy” is a 6-month intensive Advanced Backend Engineering Boot Camp to produce great backend engineers.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://backendweeky.dev/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;Join Backend Weekly:&lt;/strong&gt;&lt;/a&gt; If you like posts like this, you will absolutely enjoy our exclusive weekly newsletter, sharing exclusive backend engineering resources to help you become a great Backend Engineer.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://getbackendjobs.com/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;Get Backend Jobs:&lt;/strong&gt;&lt;/a&gt; Find over 2,000+ Tailored International Remote Backend Jobs or Reach 50,000+ backend engineers on the #1 Backend Engineering Job Board.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Originally published at&lt;/em&gt; &lt;a href="https://blog.masteringbackend.com/how-to-become-an-ai-engineer-from-a-java-developer-using-spring-ai" rel="noopener noreferrer"&gt;&lt;em&gt;https://blog.masteringbackend.com&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;




</description>
      <category>backenddevelopment</category>
      <category>javadeveloper</category>
      <category>ai</category>
      <category>springai</category>
    </item>
    <item>
      <title>Mastering @RequestHeader in Spring Boot</title>
      <dc:creator>Jane</dc:creator>
      <pubDate>Thu, 30 Apr 2026 10:00:30 +0000</pubDate>
      <link>https://dev.to/masteringbackend/mastering-requestheader-in-spring-boot-55oj</link>
      <guid>https://dev.to/masteringbackend/mastering-requestheader-in-spring-boot-55oj</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxqv0zlh3bbl1qn22805b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxqv0zlh3bbl1qn22805b.png" alt="title" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Learn how to use &lt;strong&gt;&lt;em&gt;@RequestHeader&lt;/em&gt;&lt;/strong&gt; in Spring Boot to handle HTTP headers for authentication, metadata, and client information with practical real-world examples.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is @RequestHeader
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;@RequestHeader&lt;/em&gt;&lt;/strong&gt; is a Spring Boot annotation used to bind HTTP header values to method parameters in a controller. It is mainly used to handle metadata rather than core business data. For example, headers like &lt;strong&gt;&lt;em&gt;Authorization,&lt;/em&gt;&lt;/strong&gt;  &lt;strong&gt;&lt;em&gt;Content-Type, or&lt;/em&gt;&lt;/strong&gt;  &lt;strong&gt;&lt;em&gt;User-Agent&lt;/em&gt;&lt;/strong&gt; provide additional context about the request.&lt;/p&gt;

&lt;p&gt;In real-world systems, it is commonly used for authentication (JWT tokens), request tracing (request IDs), and API versioning. It supports required, optional, and default values, making it flexible for different use cases. Proper use of headers improves API security, traceability, and communication between distributed systems.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;@RequestHeader i&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;s used in Spring Boot to extract values from HTTP request headers and bind them to method parameters, commonly for metadata like authentication tokens or client information in REST APIs.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In Spring Boot, &lt;strong&gt;&lt;em&gt;@RequestHeader&lt;/em&gt;&lt;/strong&gt; is used to extract values from HTTP request headers and bind them to method parameters. Headers usually contain metadata such as authentication tokens, content types, or client details.&lt;/p&gt;

&lt;p&gt;Let’s start with a simple example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@GetMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/api/data"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getData&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nd"&gt;@RequestHeader&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"User-Agent"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;userAgent&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Client: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;userAgent&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When a request is made, Spring extracts the &lt;strong&gt;&lt;em&gt;User-Agent&lt;/em&gt;&lt;/strong&gt; header value and passes it to the method.&lt;/p&gt;

&lt;p&gt;Now consider a real-world scenario where you need to validate an authentication token:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@GetMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/api/secure"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;secureApi&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nd"&gt;@RequestHeader&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Authorization"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Token: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In production systems, this token is usually validated before processing the request.&lt;/p&gt;

&lt;p&gt;You can also make headers optional:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@GetMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/api/info"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getInfo&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
    &lt;span class="nd"&gt;@RequestHeader&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"X-Request-Id"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;required&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;requestId&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Request ID: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;requestId&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or provide default values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@GetMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/api/version"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getVersion&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
    &lt;span class="nd"&gt;@RequestHeader&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"version"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;defaultValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"v1"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"API Version: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For multiple headers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@GetMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/api/headers"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getHeaders&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nd"&gt;@RequestHeader&lt;/span&gt; &lt;span class="nc"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toString&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Spring Boot, while &lt;strong&gt;&lt;em&gt;@RequestHeader&lt;/em&gt;&lt;/strong&gt; is commonly used to extract individual header values, you can also use &lt;strong&gt;&lt;em&gt;HttpHeaders&lt;/em&gt;&lt;/strong&gt; to handle multiple headers in a more flexible and scalable way. Let's look at a basic example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@GetMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/headers/http-headers"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;readHeaders&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nd"&gt;@RequestHeader&lt;/span&gt; &lt;span class="nc"&gt;HttpHeaders&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"User-Agent: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"User-Agent"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the entire request header is mapped into a &lt;strong&gt;&lt;em&gt;HttpHeaders&lt;/em&gt;&lt;/strong&gt; object, allowing you to access any header dynamically. Now consider a real-world scenario where you want to track client information and location:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@GetMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/headers/http-headers"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;readRequestHeadersWithHttpHeaders&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
        &lt;span class="nd"&gt;@RequestHeader&lt;/span&gt; &lt;span class="nc"&gt;HttpHeaders&lt;/span&gt; &lt;span class="n"&gt;requestHeaders&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Received: "&lt;/span&gt; 
        &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;requestHeaders&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"User-Agent"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; 
        &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" "&lt;/span&gt; 
        &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;requestHeaders&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"User-Location"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example request headers:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;User-Agent: Chrome&lt;/em&gt;&lt;/strong&gt;  &lt;strong&gt;&lt;em&gt;User-Location: India&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This approach is very useful in production systems like microservices, where multiple headers such as &lt;strong&gt;&lt;em&gt;Authorization,&lt;/em&gt;&lt;/strong&gt;  &lt;strong&gt;&lt;em&gt;X-Request-Id,&lt;/em&gt;&lt;/strong&gt;  &lt;strong&gt;&lt;em&gt;User-Agent,&lt;/em&gt;&lt;/strong&gt; and custom headers are passed in every request.&lt;/p&gt;

&lt;p&gt;In real-world applications like microservices or CRM systems, &lt;strong&gt;&lt;em&gt;@RequestHeader&lt;/em&gt;&lt;/strong&gt; is widely used for passing JWT tokens, tracking request IDs, handling API versioning, and managing client-specific data.&lt;/p&gt;

&lt;p&gt;Best practices include validating sensitive headers like Authorization, avoiding overuse of headers for business data, and keeping header usage consistent across APIs.&lt;/p&gt;

&lt;p&gt;Using &lt;strong&gt;&lt;em&gt;@RequestHeader&lt;/em&gt;&lt;/strong&gt; properly ensures secure, scalable, and well-structured APIs in production environments.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Have a great one!!!&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Author: &lt;a href="https://blog.masteringbackend.com/authors/ayush" rel="noopener noreferrer"&gt;Ayush Shrivastava&lt;/a&gt;
&lt;/h3&gt;




&lt;h3&gt;
  
  
  Thank you for being a part of the community
&lt;/h3&gt;

&lt;p&gt;Before you go:&lt;/p&gt;

&lt;h3&gt;
  
  
  Whenever you’re ready
&lt;/h3&gt;

&lt;p&gt;There are 4 ways we can help you become a great backend engineer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://masteringbackend.com/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;The MB Platform:&lt;/strong&gt;&lt;/a&gt; Join thousands of backend engineers learning backend engineering. Build real-world backend projects, learn from expert-vetted courses and roadmaps, track your learning and set schedules, and solve backend engineering tasks, exercises, and challenges.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://masteringbackend.com/academy?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;The MB Academy:&lt;/strong&gt;&lt;/a&gt; The “MB Academy” is a 6-month intensive Advanced Backend Engineering Boot Camp to produce great backend engineers.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://backendweeky.dev/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;Join Backend Weekly:&lt;/strong&gt;&lt;/a&gt; If you like posts like this, you will absolutely enjoy our exclusive weekly newsletter, sharing exclusive backend engineering resources to help you become a great Backend Engineer.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://getbackendjobs.com/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;Get Backend Jobs:&lt;/strong&gt;&lt;/a&gt; Find over 2,000+ Tailored International Remote Backend Jobs or Reach 50,000+ backend engineers on the #1 Backend Engineering Job Board.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Originally published at&lt;/em&gt; &lt;a href="https://blog.masteringbackend.com/mastering-request-header-in-spring-boot" rel="noopener noreferrer"&gt;&lt;em&gt;https://blog.masteringbackend.com&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;




</description>
      <category>backenddevelopment</category>
      <category>springboot</category>
      <category>jwttoken</category>
      <category>authentication</category>
    </item>
    <item>
      <title>Implementing Rate Limiting for AI APIs</title>
      <dc:creator>Jane</dc:creator>
      <pubDate>Wed, 29 Apr 2026 10:00:30 +0000</pubDate>
      <link>https://dev.to/masteringbackend/implementing-rate-limiting-for-ai-apis-2lbb</link>
      <guid>https://dev.to/masteringbackend/implementing-rate-limiting-for-ai-apis-2lbb</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnlv3u4y6yebnn5qb7vp2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnlv3u4y6yebnn5qb7vp2.png" alt="title" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Rate limiting is what keeps your APIs stable under pressure. It helps to control how many requests a user or system can make, especially when working with heavy AI models.&lt;/p&gt;

&lt;p&gt;This guide walks through how API rate limiting works and how you can implement it in real-world systems. Exploring common strategies and learning how to handle the rate limit and errors helps you across different stacks.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to Implement Rate Limiting in an API (Step by Step)
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Step 1: Define what you want to limit
&lt;/h4&gt;

&lt;p&gt;Start by selecting the key used to track requests. Which are usually:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;IP address (simple, but less accurate)&lt;/li&gt;
&lt;li&gt;User ID (better for authenticated systems)&lt;/li&gt;
&lt;li&gt;API key (common for AI APIs)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For an AI system, API keys or user IDs give more control and fairness.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 2: Set a clear rate limit policy
&lt;/h4&gt;

&lt;p&gt;Decide the number of requests you want within a particular time.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;100 requests per minute per user&lt;/li&gt;
&lt;li&gt;1,000 requests per hour per API key&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Keep the limits realistic. Most AI endpoints are often resource-heavy, so be sure to reduce the limits where necessary.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 3: Choose a rate-limiting algorithm
&lt;/h4&gt;

&lt;p&gt;Make sure you pick a strategy based on your use case:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fixed window: it’s simple, but can cause bursts at window edges&lt;/li&gt;
&lt;li&gt;Sliding window: it gives smoother control over traffic&lt;/li&gt;
&lt;li&gt;Token bucket: very flexible, and allows short bursts while enforcing limits&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For most AI APIs, a token bucket or a sliding window works best.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 4: Save request counts efficiently
&lt;/h4&gt;

&lt;p&gt;You need a fast storage layer that can help you track requests in real time.&lt;/p&gt;

&lt;p&gt;Here are some common options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In-memory store (Redis is widely used)&lt;/li&gt;
&lt;li&gt;Application memory (only for single-instance apps)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example Redis key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rate_limit:user_123
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 5: Intercept requests with middleware
&lt;/h4&gt;

&lt;p&gt;Rate limiting should run before your main logic. In some frameworks, this is done using middleware, which helps to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Extracts the identifier (IP, user ID, or API key)&lt;/li&gt;
&lt;li&gt;Check the current request count&lt;/li&gt;
&lt;li&gt;Decides whether to allow or reject a request&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Step 6: Enforce the limit
&lt;/h4&gt;

&lt;p&gt;If a request exceeds its limit, block it immediately by returning a standard HTTP response:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="k"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;1.1&lt;/span&gt; &lt;span class="m"&gt;429&lt;/span&gt; &lt;span class="ne"&gt;Too Many Requests&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Include helpful headers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;X-RateLimit-Limit: 100
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 60
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This helps clients understand when they can retry.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 7: Handle allowed requests
&lt;/h4&gt;

&lt;p&gt;If the request is within limits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Increase the counter&lt;/li&gt;
&lt;li&gt;Forward the request to the API handler&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Keep this step fast. Rate limiting should not introduce noticeable latency.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 8: Add retry and backoff guidance
&lt;/h4&gt;

&lt;p&gt;Clients should not retry immediately after hitting limits, encouraging exponential backoff helps to reduce pressure on your API during spikes.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 9: Log and monitor rate limit activity
&lt;/h4&gt;

&lt;p&gt;Be sure to track:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The number of blocked requests&lt;/li&gt;
&lt;li&gt;The most active users or API keys&lt;/li&gt;
&lt;li&gt;The patterns of abuse&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This will help to fine-tune limits and detect misuse early.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 10: Test under load
&lt;/h4&gt;

&lt;p&gt;Simulate high traffic before deploying, and be sure to check:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Whether limits are enforced correctly&lt;/li&gt;
&lt;li&gt;If legitimate users are blocked too early&lt;/li&gt;
&lt;li&gt;How the system behaves under burst traffic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Rate limiting should protect your API without breaking normal usage.&lt;/p&gt;

&lt;h3&gt;
  
  
  Implementing Rate Limiting in C-Based APIs
&lt;/h3&gt;

&lt;p&gt;C-based APIs mostly run on high-performance environments where efficiency matters. For this, rate limiting needs to be fast, memory-conscious, and thread-safe by making sure to choose a lightweight tracking mechanism.&lt;/p&gt;

&lt;p&gt;In C, this is usually done with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;in-memory hash tables&lt;/li&gt;
&lt;li&gt;shared memory (for multi-process setups)&lt;/li&gt;
&lt;li&gt;external stores like Redis (for distributed systems)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Defining a rate limit structure
&lt;/h4&gt;

&lt;p&gt;Create a struct to track request counts and timing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="k"&gt;typedef&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;request_count&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;time_t&lt;/span&gt; &lt;span class="n"&gt;window_start&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;RateLimit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Map the key as an IP address or API key.&lt;/p&gt;

&lt;p&gt;Use a hash table for fast lookups, and each incoming request should:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Extract the identifier (IP or API key)&lt;/li&gt;
&lt;li&gt;Look up its rate limit record&lt;/li&gt;
&lt;li&gt;Update or reset the counter&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Example using pseudo-hash map logic:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;RateLimit&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;rl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;get_rate_limit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;current_time&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;window_start&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;WINDOW_SIZE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;request_count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;window_start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;current_time&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;request_count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check the count before processing the request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rl&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;request_count&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;MAX_REQUESTS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;429&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Too Many Requests&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Avoid heavy operations in this path.&lt;/p&gt;

&lt;p&gt;C-based APIs often run in multi-threaded or multi-process environments, and the race conditions can break rate-limiting logic.&lt;/p&gt;

&lt;p&gt;Use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;mutex locks (for threads)&lt;/li&gt;
&lt;li&gt;atomic operations (for counters)&lt;/li&gt;
&lt;li&gt;shared memory locks (for multi-process systems)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example with a mutex:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;pthread_mutex_lock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;lock&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="cm"&gt;/* update rate limit */&lt;/span&gt;
&lt;span class="n"&gt;pthread_mutex_unlock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;lock&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep lock duration short to avoid performance bottlenecks.&lt;/p&gt;

&lt;p&gt;Each active user or IP consumes memory, and without cleanup, the memory usage grows over time.&lt;/p&gt;

&lt;p&gt;Implement expiration:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;remove entries after inactivity&lt;/li&gt;
&lt;li&gt;periodically clean old records&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This prevents memory leaks in long-running services.&lt;/p&gt;

&lt;h4&gt;
  
  
  Use Redis for distributed rate limiting
&lt;/h4&gt;

&lt;p&gt;If your C API runs across multiple servers, in-memory tracking is not going to be enough.&lt;/p&gt;

&lt;p&gt;Use Redis with atomic operations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="n"&gt;INCR&lt;/span&gt; &lt;span class="n"&gt;rate_limit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;user_123&lt;/span&gt;
&lt;span class="n"&gt;EXPIRE&lt;/span&gt; &lt;span class="n"&gt;rate_limit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;user_123&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This ensures consistent limits across all instances.&lt;/p&gt;

&lt;p&gt;In C environments, simplicity often wins.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fixed window: easiest to implement&lt;/li&gt;
&lt;li&gt;Token bucket: better for handling bursts&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A token bucket can be implemented with a counter that refills over time.&lt;/p&gt;

&lt;h4&gt;
  
  
  Return proper HTTP responses
&lt;/h4&gt;

&lt;p&gt;Even in C-based servers, follow standard responses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="k"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;1.1&lt;/span&gt; &lt;span class="m"&gt;429&lt;/span&gt; &lt;span class="ne"&gt;Too Many Requests&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Be sure to include headers for better client handling&lt;/p&gt;

&lt;p&gt;C systems are often used for high-throughput APIs to help simulate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;burst traffic&lt;/li&gt;
&lt;li&gt;concurrent requests&lt;/li&gt;
&lt;li&gt;edge cases around time windows&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Efficient rate limiting in C rests on tight control rather than memory, concurrency, and execution time. If implemented correctly, it protects your API without slowing it down.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adding Rate Limiting to Python and FastAPI Services
&lt;/h3&gt;

&lt;p&gt;Rate limiting in Python APIs is normally implemented at the middleware or dependency level. For FastAPI, this approach keeps the logic centralized and easy to reuse across routes.&lt;/p&gt;

&lt;p&gt;For most AI APIs, API keys or user IDs give better control than IP-based limits.&lt;/p&gt;

&lt;p&gt;Instead of trying to build everything from scratch, use proven tools like &lt;strong&gt;&lt;em&gt;slowapi or&lt;/em&gt;&lt;/strong&gt;  &lt;strong&gt;&lt;em&gt;fastapi-limiter, and&lt;/em&gt;&lt;/strong&gt; integrate them directly with FastAPI and reduce implementation complexity.&lt;/p&gt;

&lt;p&gt;Example using &lt;strong&gt;&lt;em&gt;fastapi-limiter&lt;/em&gt;&lt;/strong&gt; with Redis:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;fastapi&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;FastAPI&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Request&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;fastapi.responses&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;JSONResponse&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;fastapi_limiter&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;FastAPILimiter&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;fastapi_limiter.depends&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;RateLimiter&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;aioredis&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;FastAPI&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="nd"&gt;@app.on_event&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;startup&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;startup&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;redis&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;aioredis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;redis://localhost&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;FastAPILimiter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nd"&gt;@app.get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/chat&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dependencies&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Depends&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;RateLimiter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;times&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;seconds&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;))])&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;chat_endpoint&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;message&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Request allowed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This limits requests to 5 per minute per client and each request:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Extracts a unique identifier&lt;/li&gt;
&lt;li&gt;Stores or increments a counter in Redis&lt;/li&gt;
&lt;li&gt;Checks if the limit is exceeded&lt;/li&gt;
&lt;li&gt;Blocks or allows the request&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Redis is mostly used because it supports atomic operations and works well in distributed systems.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nd"&gt;@app.get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/inference&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dependencies&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Depends&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;RateLimiter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;times&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;seconds&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;))])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This keeps resource-heavy endpoints protected.&lt;/p&gt;

&lt;p&gt;When a limit has been exceeded, FastAPI automatically returns:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;429 Too Many Requests
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can customize the response:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nd"&gt;@app.exception_handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;429&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;rate_limit_handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;exc&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;JSONResponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;status_code&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;429&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;detail&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Rate limit exceeded. Try again later.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want a global limit across all routes, applying middleware instead of per-route dependencies works, and it ensures every request passes through the same rate-limiting logic.&lt;/p&gt;

&lt;p&gt;In production, most FastAPI apps often run with multiple workers, which may stop in-memory counters from syncing across instances.&lt;/p&gt;

&lt;p&gt;Always use a shared store like Redis for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;consistent limits&lt;/li&gt;
&lt;li&gt;distributed deployments&lt;/li&gt;
&lt;li&gt;horizontal scaling&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;FastAPI makes rate limiting straightforward when combined with Redis and middleware patterns. The most important part is keeping it efficient, consistent, and aligned with how your API is being used.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Have a great one!!!&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Author: &lt;a href="https://blog.masteringbackend.com/authors/Toluwanimi" rel="noopener noreferrer"&gt;Toluwanimi Fawole&lt;/a&gt;
&lt;/h3&gt;




&lt;h3&gt;
  
  
  Thank you for being a part of the community
&lt;/h3&gt;

&lt;p&gt;Before you go:&lt;/p&gt;

&lt;h3&gt;
  
  
  Whenever you’re ready
&lt;/h3&gt;

&lt;p&gt;There are 4 ways we can help you become a great backend engineer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://masteringbackend.com/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;The MB Platform:&lt;/strong&gt;&lt;/a&gt; Join thousands of backend engineers learning backend engineering. Build real-world backend projects, learn from expert-vetted courses and roadmaps, track your learning and set schedules, and solve backend engineering tasks, exercises, and challenges.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://masteringbackend.com/academy?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;The MB Academy:&lt;/strong&gt;&lt;/a&gt; The “MB Academy” is a 6-month intensive Advanced Backend Engineering Boot Camp to produce great backend engineers.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://backendweeky.dev/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;Join Backend Weekly:&lt;/strong&gt;&lt;/a&gt; If you like posts like this, you will absolutely enjoy our exclusive weekly newsletter, sharing exclusive backend engineering resources to help you become a great Backend Engineer.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://getbackendjobs.com/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;Get Backend Jobs:&lt;/strong&gt;&lt;/a&gt; Find over 2,000+ Tailored International Remote Backend Jobs or Reach 50,000+ backend engineers on the #1 Backend Engineering Job Board.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Originally published at&lt;/em&gt; &lt;a href="https://blog.masteringbackend.com/implementing-rate-limiting-for-ai-ap-is" rel="noopener noreferrer"&gt;&lt;em&gt;https://blog.masteringbackend.com&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;




</description>
      <category>redis</category>
      <category>ratelimiting</category>
      <category>ai</category>
      <category>api</category>
    </item>
    <item>
      <title>Mastering @RequestParam in Spring Boot</title>
      <dc:creator>Jane</dc:creator>
      <pubDate>Tue, 21 Apr 2026 09:00:00 +0000</pubDate>
      <link>https://dev.to/masteringbackend/mastering-requestparam-in-spring-boot-2m17</link>
      <guid>https://dev.to/masteringbackend/mastering-requestparam-in-spring-boot-2m17</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo9h918qt9h8my7xr0hct.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo9h918qt9h8my7xr0hct.png" alt="Mastering @RequestParam in Spring Boot" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Learn how to use  &lt;code&gt;@RequestParam&lt;/code&gt;  in Spring Boot to handle query parameters effectively with practical examples from real-world scenarios like search, filtering, and pagination.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is  &lt;code&gt;@RequestParam&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;@RequestParam&lt;/code&gt;  is a Spring Boot annotation used to bind query parameters from the URL to method parameters in a controller. Unlike  &lt;code&gt;@PathVariable&lt;/code&gt;, which is used for identifying resources,  &lt;code&gt;@RequestParam&lt;/code&gt;  is mainly used for filtering, searching, and optional data inputs.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;@RequestParam&lt;/code&gt; &lt;strong&gt;is used in Spring Boot to extract query parameters from the URL and bind them to method parameters for filtering, searching, or optional inputs in REST APIs.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For example,  &lt;code&gt;/products?category=books&amp;amp;price=500&lt;/code&gt; uses query parameters to filter results. It is widely used in real-world applications like e-commerce for search functionality, pagination, and sorting. It also supports optional values, default values, and multiple inputs. This makes APIs more flexible without changing the endpoint structure, improving usability and scalability in production systems.&lt;/p&gt;

&lt;p&gt;In Spring Boot,  &lt;code&gt;@RequestParam&lt;/code&gt; is used to extract values from query parameters in the URL. It is commonly used when you want to pass optional or filtering data to your APIs without changing the URL structure.&lt;/p&gt;

&lt;p&gt;Let’s start with a simple example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@GetMapping("/users")
public String getUserById(@RequestParam Long userId) {
    return "User ID: " + userId;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When a request like  &lt;code&gt;/users?userId=101&lt;/code&gt; is made, Spring maps  &lt;code&gt;101&lt;/code&gt; to the  &lt;code&gt;userId&lt;/code&gt; parameter.&lt;/p&gt;

&lt;p&gt;Now consider a real-world e-commerce scenario where users search for products:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@GetMapping("/products")
public String searchProducts(@RequestParam String category,
                             @RequestParam String sortBy) {
    return "Category: " + category + ", Sort By: " + sortBy;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Example request:  &lt;code&gt;/products?category=electronics&amp;amp;sortBy=price&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can also make parameters optional:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@GetMapping("/products")
public String getProducts(@RequestParam(required = false) String category) {
    return "Category: " + category;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Or provide default values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@GetMapping("/products")
public String getProducts(
    @RequestParam(defaultValue = "all") String category) {
    return "Category: " + category;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For multiple values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@GetMapping("/products/filter")
public String filterProducts(@RequestParam List&amp;lt;String&amp;gt; tags) {
    return "Tags: " + tags;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In real-world systems like CRM or booking platforms,  &lt;code&gt;@RequestParam&lt;/code&gt; is used for filtering data such as date ranges, status, pagination  &lt;code&gt;(page,&lt;/code&gt;  &lt;code&gt;size)&lt;/code&gt;, or sorting options.&lt;/p&gt;

&lt;p&gt;Best practices include keeping query parameters meaningful, using default values for better UX, validating inputs, and avoiding too many parameters in a single API.&lt;/p&gt;

&lt;p&gt;Using  &lt;code&gt;@RequestParam&lt;/code&gt; properly helps build flexible, scalable, and user-friendly APIs aligned with REST standards.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Have a great one!!!&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Author:  &lt;a href="https://blog.masteringbackend.com/authors/ayush" rel="noopener noreferrer"&gt;Ayush Shrivastava&lt;/a&gt;
&lt;/h3&gt;




&lt;h2&gt;
  
  
  Thank you for being a part of the community
&lt;/h2&gt;

&lt;p&gt;Before you go:&lt;/p&gt;

&lt;h2&gt;
  
  
  Whenever you’re ready
&lt;/h2&gt;

&lt;p&gt;There are 4 ways we can help you become a great backend engineer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://masteringbackend.com/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;The MB Platform:&lt;/strong&gt;&lt;/a&gt;  Join thousands of backend engineers learning backend engineering. Build real-world backend projects, learn from expert-vetted courses and roadmaps, track your learning and set schedules, and solve backend engineering tasks, exercises, and challenges.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://masteringbackend.com/academy?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;The MB Academy:&lt;/strong&gt;&lt;/a&gt;  The “MB Academy” is a 6-month intensive Advanced Backend Engineering Boot Camp to produce great backend engineers.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://backendweeky.dev/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;Join Backend Weekly:&lt;/strong&gt;&lt;/a&gt;  If you like posts like this, you will absolutely enjoy our exclusive weekly newsletter, sharing exclusive backend engineering resources to help you become a great Backend Engineer.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://getbackendjobs.com/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;Get Backend Jobs:&lt;/strong&gt;&lt;/a&gt;  Find over 2,000+ Tailored International Remote Backend Jobs or Reach 50,000+ backend engineers on the #1 Backend Engineering Job Board.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>springboot</category>
      <category>reactquery</category>
      <category>backenddevelopment</category>
      <category>restapi</category>
    </item>
    <item>
      <title>Difference Between OpenAI API Key and Azure OpenAI API Key</title>
      <dc:creator>Jane</dc:creator>
      <pubDate>Mon, 20 Apr 2026 09:00:00 +0000</pubDate>
      <link>https://dev.to/masteringbackend/difference-between-openai-api-key-and-azure-openai-api-key-3j2b</link>
      <guid>https://dev.to/masteringbackend/difference-between-openai-api-key-and-azure-openai-api-key-3j2b</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5w0okmxbae99wgte7u4g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5w0okmxbae99wgte7u4g.png" alt="Difference Between OpenAI API Key and Azure OpenAI API Key" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Developers can access AI models using two main platforms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;OpenAI&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Azure OpenAI&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both provide access to similar AI models, but the way authentication and deployment work is different.&lt;/p&gt;

&lt;p&gt;In this article, we will understand the difference between OpenAI API keys and Azure OpenAI API keys.&lt;/p&gt;

&lt;h3&gt;
  
  
  OpenAI API Key
&lt;/h3&gt;

&lt;p&gt;OpenAI provides direct access to AI models through its own platform.&lt;/p&gt;

&lt;p&gt;Developers can sign up on the OpenAI website and generate an API key.&lt;/p&gt;

&lt;p&gt;Example platform:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://platform.openai.com/" rel="noopener noreferrer"&gt;https://platform.openai.com&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Steps to Get OpenAI API Key
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Login to OpenAI platform.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go to  &lt;strong&gt;API Keys&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click  &lt;strong&gt;Create New Secret Key&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sk-xxxxxxxxxxxxxxxxxxxxxxxx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This key can be used directly with OpenAI APIs.&lt;/p&gt;

&lt;p&gt;Example endpoint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://api.openai.com/v1/chat/completions
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Azure OpenAI API Key
&lt;/h3&gt;

&lt;p&gt;Azure OpenAI provides OpenAI models through Microsoft Azure infrastructure.&lt;/p&gt;

&lt;p&gt;Instead of using OpenAI servers directly, the requests go through Azure services.&lt;/p&gt;

&lt;p&gt;Azure OpenAI requires:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Azure resource&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Model deployment&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Endpoint&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;API key&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example API Key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;xxxxxxxxxxxxxxxxxxxxxxxx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Example Endpoint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://openai-demo.openai.azure.com/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Differences
&lt;/h3&gt;

&lt;p&gt;OpenAI API&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Hosted by OpenAI&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Direct API usage&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Simple setup&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Single endpoint&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Azure OpenAI&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Hosted on Microsoft Azure&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Requires resource creation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Requires model deployment&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Uses Azure endpoint&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  When to Use OpenAI
&lt;/h3&gt;

&lt;p&gt;Use OpenAI when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You want quick setup&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You are building prototypes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You want direct API access&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  When to Use Azure OpenAI
&lt;/h3&gt;

&lt;p&gt;Use Azure OpenAI when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You need enterprise security&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You want Azure integration&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Your organization already uses Azure cloud&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You need regional deployment&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Both OpenAI and Azure OpenAI provide access to powerful AI models.&lt;/p&gt;

&lt;p&gt;OpenAI is easier for quick development, while Azure OpenAI is better suited for enterprise applications that require scalability, security, and integration with other Azure services.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Have a great one!!!&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Author: &lt;a href="https://blog.masteringbackend.com/authors/ayush" rel="noopener noreferrer"&gt;Ayush Shrivastava&lt;/a&gt;
&lt;/h3&gt;




&lt;h3&gt;
  
  
  Thank you for being a part of the community
&lt;/h3&gt;

&lt;p&gt;Before you go:&lt;/p&gt;

&lt;h3&gt;
  
  
  Whenever you’re ready
&lt;/h3&gt;

&lt;p&gt;There are 4 ways we can help you become a great backend engineer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://masteringbackend.com/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;The MB Platform:&lt;/strong&gt;&lt;/a&gt; Join thousands of backend engineers learning backend engineering. Build real-world backend projects, learn from expert-vetted courses and roadmaps, track your learning and set schedules, and solve backend engineering tasks, exercises, and challenges.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://masteringbackend.com/academy?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;The MB Academy:&lt;/strong&gt;&lt;/a&gt; The “MB Academy” is a 6-month intensive Advanced Backend Engineering Boot Camp to produce great backend engineers.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://backendweeky.dev/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;Join Backend Weekly:&lt;/strong&gt;&lt;/a&gt; If you like posts like this, you will absolutely enjoy our exclusive weekly newsletter, sharing exclusive backend engineering resources to help you become a great Backend Engineer.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://getbackendjobs.com/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;Get Backend Jobs:&lt;/strong&gt;&lt;/a&gt; Find over 2,000+ Tailored International Remote Backend Jobs or Reach 50,000+ backend engineers on the #1 Backend Engineering Job Board.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>openai</category>
      <category>api</category>
      <category>backenddevelopment</category>
      <category>azure</category>
    </item>
    <item>
      <title>How to Create an Azure OpenAI Resource and Deploy Your First Model.</title>
      <dc:creator>Jane</dc:creator>
      <pubDate>Fri, 17 Apr 2026 09:00:00 +0000</pubDate>
      <link>https://dev.to/masteringbackend/how-to-create-an-azure-openai-resource-and-deploy-your-first-model-5hij</link>
      <guid>https://dev.to/masteringbackend/how-to-create-an-azure-openai-resource-and-deploy-your-first-model-5hij</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm99yta2rwatuq28ga1t0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm99yta2rwatuq28ga1t0.png" alt="How to Create an Azure OpenAI Resource and Deploy Your First Model" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Azure OpenAI allows developers to use powerful AI models such as GPT-4, GPT-4o, and GPT-3.5 directly from the Azure cloud. These models can be used to build chatbots, AI assistants, content generators, and many intelligent applications.&lt;/p&gt;

&lt;p&gt;In this article, you will learn how to create an Azure OpenAI resource, deploy a model, and get the API key required to use the service in your application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;Before starting, make sure you have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;An Azure account&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Access to the Azure Portal&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Azure OpenAI service is enabled for your subscription&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you do not have an Azure account, you can create one from the Azure website.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Create Azure OpenAI Resource
&lt;/h3&gt;

&lt;p&gt;First, you need to create an Azure OpenAI resource.&lt;/p&gt;

&lt;p&gt;Open the Azure Portal:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://portal.azure.com/" rel="noopener noreferrer"&gt;https://portal.azure.com&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Steps
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Login to the Azure Portal.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the search bar, type  &lt;strong&gt;Azure OpenAI&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click  &lt;strong&gt;Create&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now fill the required fields.&lt;/p&gt;

&lt;h4&gt;
  
  
  Configuration
&lt;/h4&gt;

&lt;p&gt;Resource Group&lt;/p&gt;

&lt;p&gt;Create a new resource group or select an existing one.&lt;/p&gt;

&lt;p&gt;Region&lt;/p&gt;

&lt;p&gt;Choose a supported region such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;East US&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Sweden Central&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Name&lt;/p&gt;

&lt;p&gt;Enter a unique resource name.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;openai-demo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Pricing Tier&lt;/p&gt;

&lt;p&gt;Select  &lt;strong&gt;Standard&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;After filling the details:&lt;/p&gt;

&lt;p&gt;Click  &lt;strong&gt;Review + Create&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Then click  &lt;strong&gt;Create&lt;/strong&gt;  to deploy the resource.&lt;/p&gt;

&lt;p&gt;Deployment usually takes around one to two minutes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Deploy a Model
&lt;/h3&gt;

&lt;p&gt;Once the resource is created, you need to deploy a model.&lt;/p&gt;

&lt;h4&gt;
  
  
  Steps
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open the Azure OpenAI resource you created.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the left menu, click  &lt;strong&gt;Model Deployments&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click  &lt;strong&gt;Deploy Model&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now select a model.&lt;/p&gt;

&lt;h3&gt;
  
  
  Recommended Models
&lt;/h3&gt;

&lt;p&gt;For most applications, these models work well:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;gpt-4o-mini&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Fast and cost efficient model.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;gpt-35-turbo&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Popular chat model.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deployment Configuration
&lt;/h3&gt;

&lt;p&gt;Model&lt;/p&gt;

&lt;p&gt;Select the model you want.&lt;/p&gt;

&lt;p&gt;Deployment Name&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gpt-4o-mini
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click  &lt;strong&gt;Deploy&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Azure will now create the model deployment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Get API Credentials
&lt;/h3&gt;

&lt;p&gt;To call the Azure OpenAI API from your application, you need an API key and endpoint.&lt;/p&gt;

&lt;h4&gt;
  
  
  Steps
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open the Azure OpenAI resource.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click  &lt;strong&gt;Keys and Endpoint&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You will see the following information.&lt;/p&gt;

&lt;p&gt;API Key 1&lt;/p&gt;

&lt;p&gt;API Key 2&lt;/p&gt;

&lt;p&gt;Endpoint&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;API KEY
xxxxxxxxxxxxxxxxxxxxxxxx

ENDPOINT
https://openai-demo.openai.azure.com/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can use either  &lt;strong&gt;Key 1 or Key 2&lt;/strong&gt;  in your application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example API Endpoint
&lt;/h3&gt;

&lt;p&gt;Your application will send requests to the endpoint.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://openai-demo.openai.azure.com/openai/deployments/gpt-4o-mini/chat/completions?api-version=2024-02-15-preview
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Your request must include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;API Key&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Endpoint&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Deployment Name&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Azure OpenAI makes it easy to use powerful AI models in enterprise applications. The basic process involves three steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create an Azure OpenAI resource&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Deploy a model such as gpt-4o-mini&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Get API credentials and endpoint&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Once these steps are completed, you can start building AI-powered applications using Azure OpenAI.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Have a great one!!!&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Author: &lt;a href="https://blog.masteringbackend.com/authors/ayush" rel="noopener noreferrer"&gt;Ayush Shrivastava&lt;/a&gt;
&lt;/h3&gt;




&lt;h3&gt;
  
  
  Thank you for being a part of the community
&lt;/h3&gt;

&lt;p&gt;Before you go:&lt;/p&gt;

&lt;h3&gt;
  
  
  Whenever you’re ready
&lt;/h3&gt;

&lt;p&gt;There are 4 ways we can help you become a great backend engineer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://masteringbackend.com/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;The MB Platform:&lt;/strong&gt;&lt;/a&gt; Join thousands of backend engineers learning backend engineering. Build real-world backend projects, learn from expert-vetted courses and roadmaps, track your learning and set schedules, and solve backend engineering tasks, exercises, and challenges.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://masteringbackend.com/academy?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;The MB Academy:&lt;/strong&gt;&lt;/a&gt; The “MB Academy” is a 6-month intensive Advanced Backend Engineering Boot Camp to produce great backend engineers.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://backendweeky.dev/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;Join Backend Weekly:&lt;/strong&gt;&lt;/a&gt; If you like posts like this, you will absolutely enjoy our exclusive weekly newsletter, sharing exclusive backend engineering resources to help you become a great Backend Engineer.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://getbackendjobs.com/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;Get Backend Jobs:&lt;/strong&gt;&lt;/a&gt; Find over 2,000+ Tailored International Remote Backend Jobs or Reach 50,000+ backend engineers on the #1 Backend Engineering Job Board.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>openai</category>
      <category>restapi</category>
      <category>backenddevelopment</category>
      <category>azure</category>
    </item>
    <item>
      <title>Mastering @PathVariable in Spring Boot</title>
      <dc:creator>Jane</dc:creator>
      <pubDate>Thu, 16 Apr 2026 10:00:30 +0000</pubDate>
      <link>https://dev.to/masteringbackend/mastering-pathvariable-in-spring-boot-9f1</link>
      <guid>https://dev.to/masteringbackend/mastering-pathvariable-in-spring-boot-9f1</guid>
      <description>&lt;p&gt;&lt;a href="https://blog.masteringbackend.com/authors/ayush" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffk5ojfvcn7yi5kp4p36k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffk5ojfvcn7yi5kp4p36k.png" alt="Mastering @PathVariable in Spring Boot" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Learn how to use  &lt;code&gt;@PathVariable&lt;/code&gt; in Spring Boot to build clean and RESTful APIs with practical examples from real-world scenarios like users, products, and orders.&lt;/p&gt;
&lt;h4&gt;
  
  
  What is  &lt;code&gt;@PathVariable&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;@PathVariable&lt;/code&gt; in Spring Boot is an annotation used to bind values from the URL directly to method parameters in a controller. It is mainly used in REST APIs where resources are identified using hierarchical URLs. For example, in  &lt;code&gt;/users/101,&lt;/code&gt;  the value  &lt;code&gt;101&lt;/code&gt; represents a specific user and is captured using  &lt;code&gt;@PathVariable.&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;@PathVariable&lt;/code&gt; is used in Spring Boot to extract values from the URL path and bind them to method parameters to identify specific resources in REST APIs.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It differs from query parameters because it is part of the URL path, making APIs more readable and meaningful. In real-world systems like e-commerce or CRM, it is commonly used to fetch specific records, such as a user, product, or order, by ID. It also supports multiple values and even dynamic mapping using a Map structure when needed.&lt;/p&gt;

&lt;p&gt;In Spring Boot,  &lt;code&gt;@PathVariable&lt;/code&gt; is used to extract dynamic values from the URL. It helps in designing RESTful APIs where resources are clearly identified using URL paths instead of query parameters.&lt;/p&gt;

&lt;p&gt;Let’s start with a simple example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@GetMapping("/users/{userId}")
public String getUser(@PathVariable Long userId) {
    return "User ID: " + userId;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When a request like  &lt;code&gt;/users/101&lt;/code&gt; is made, Spring automatically maps  &lt;code&gt;101&lt;/code&gt; to the  &lt;code&gt;userId&lt;/code&gt; variable.&lt;/p&gt;

&lt;p&gt;Now consider a real-world scenario in an e-commerce system where a user wants to view a specific product:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@GetMapping("/users/{userId}/products/{productId}")
public String getUserProduct(@PathVariable Long userId,
                             @PathVariable Long productId) {
    return "User: " + userId + ", Product: " + productId;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This makes the API intuitive and readable.&lt;/p&gt;

&lt;p&gt;You can also customize variable names:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@GetMapping("/users/{userId}/orders/{orderId}")
public String getOrder(@PathVariable(name = "userId") Long id,
                       @PathVariable Long orderId) {
    return "User: " + id + ", Order: " + orderId;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For dynamic cases, you can use a Map:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@GetMapping("/users/{userId}/address/{addressId}")
public String getAddress(@PathVariable Map&amp;lt;String, String&amp;gt; pathVars) {
    return "User: " + pathVars.get("userId") +
           ", Address: " + pathVars.get("addressId");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use our &lt;a href="https://playground.masteringbackend.com/javascript/?ref=masteringbackend&amp;amp;utm_source=masteringbackend&amp;amp;utm_medium=custom_code_editor&amp;amp;utm_campaign=blog-post" rel="noopener noreferrer"&gt;Online Code Editor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is useful when handling flexible URLs.&lt;/p&gt;

&lt;p&gt;In real-world applications like CRM or booking systems,  &lt;code&gt;@PathVariable&lt;/code&gt; is used to fetch user details, order history, or product information based on unique identifiers.&lt;/p&gt;

&lt;p&gt;Best practices include using meaningful variable names, avoiding too many path variables in one endpoint, and validating inputs properly. Also, prefer strongly typed variables over Map when possible.&lt;/p&gt;

&lt;p&gt;Using  &lt;code&gt;@PathVariable&lt;/code&gt; correctly improves API clarity, maintainability, and aligns with REST standards followed in production-grade applications.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Have a great one!!!&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Author: &lt;a href="https://blog.masteringbackend.com/authors/ayush" rel="noopener noreferrer"&gt;Ayush Shrivastava&lt;/a&gt;
&lt;/h3&gt;




&lt;h3&gt;
  
  
  Thank you for being a part of the community
&lt;/h3&gt;

&lt;p&gt;Before you go:&lt;/p&gt;

&lt;h3&gt;
  
  
  Whenever you’re ready
&lt;/h3&gt;

&lt;p&gt;There are 4 ways we can help you become a great backend engineer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://masteringbackend.com/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;The MB Platform:&lt;/strong&gt;&lt;/a&gt; Join thousands of backend engineers learning backend engineering. Build real-world backend projects, learn from expert-vetted courses and roadmaps, track your learning and set schedules, and solve backend engineering tasks, exercises, and challenges.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://masteringbackend.com/academy?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;The MB Academy:&lt;/strong&gt;&lt;/a&gt; The “MB Academy” is a 6-month intensive Advanced Backend Engineering Boot Camp to produce great backend engineers.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://backendweeky.dev/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;Join Backend Weekly:&lt;/strong&gt;&lt;/a&gt; If you like posts like this, you will absolutely enjoy our exclusive weekly newsletter, sharing exclusive backend engineering resources to help you become a great Backend Engineer.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://getbackendjobs.com/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;Get Backend Jobs:&lt;/strong&gt;&lt;/a&gt; Find over 2,000+ Tailored International Remote Backend Jobs or Reach 50,000+ backend engineers on the #1 Backend Engineering Job Board.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>restapis</category>
      <category>backenddeveloper</category>
      <category>springboot</category>
      <category>pathvariable</category>
    </item>
    <item>
      <title>TOP 5 Books Every Backend Developer Should Read</title>
      <dc:creator>Jane</dc:creator>
      <pubDate>Fri, 10 Apr 2026 10:00:30 +0000</pubDate>
      <link>https://dev.to/masteringbackend/top-5-books-every-backend-developer-should-read-3i3g</link>
      <guid>https://dev.to/masteringbackend/top-5-books-every-backend-developer-should-read-3i3g</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fal3fbvi2vt6jwd0awm6d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fal3fbvi2vt6jwd0awm6d.png" alt="title" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The world of software development is fast-paced. If you glance away to pet your cat too long, you may miss the next big framework or tool. For instance, JavaScript, one of the most popular programming languages in the world, is notorious for pushing out new frameworks as often as a developer has a bad day , which happens more often than you may think. Because of this, many developers need to get information quickly, and the best mediums to get that information come in the form of short-form videos, quick articles, and snappy courses. While we can appreciate the roles these play in keeping us up to speed with development trends, it’s still crucial to settle in with a good book once in a while.&lt;/p&gt;

&lt;p&gt;Some development books may seem intimidating judging by volume alone, but the treasures they hold within are timeless. Usually, what separates good developers from average developers is how much time they are willing to read between the lines and understand the underlying concepts that run programs, so they can be more efficient at solving problems. If you’d like to be the best backend developer you could be, have a look at these top five books backend developers should read that’ll be sure to take you to the next level of your career.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. &lt;a href="https://www.amazon.com/Designing-Data-Intensive-Applications-Reliable-Maintainable/dp/1449373321" rel="noopener noreferrer"&gt;Designing Data-Intensive Applications by Martin Kleppmann&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzlksyoxgjb6ugam7a4as.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzlksyoxgjb6ugam7a4as.jpg" alt="book1" width="800" height="1050"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This book is a classic for those seeking to understand how data works and is handled by applications. It dives into ways to optimize data, so you produce programs that retrieve and use data quickly and efficiently.&lt;/p&gt;

&lt;p&gt;Here, you’ll be looking into database storage and trade-offs that exist between different data technologies. It introduces these core trade-offs in distributed systems like consistency, availability, and scalability, which shape how real-world backend systems are designed. As a backend developer, dealing with data constantly, this book is a must-have and will help you explore the fundamental principles of data systems.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. &lt;a href="https://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882/ref=sr_1_1?crid=18P7O2XUMNHDT&amp;amp;dib=eyJ2IjoiMSJ9.G6SRByFrwqob6KQdRTDbl81VKTwojNrO2p3dvKOrV5HnjmLk2c5W8wrKiK5ot4A2_kKFGChl4MDAgKrAITsKGKzvb48MymC2fBPoPu8TbROhSOAWEcEpnNJj82Zz_z3QwgIRtCmp7kcsqw9EXKtNA-dx8cpIn03PBmFiiy25yHUuVQjcpOD9aOvO6sNDofGVS2vpgtb54RCXRMGK9jg6tnYcM3hKXR9ts-E3PkBS95E.sGiZdyjAsKdxOfqVdr5zVHra6sbqq_eXW4W4NupoVoU&amp;amp;dib_tag=se&amp;amp;keywords=clean+code+by+robert+c.+martin&amp;amp;qid=1774802512&amp;amp;s=books&amp;amp;sprefix=clean+code+%2Cstripbooks-intl-ship%2C355&amp;amp;sr=1-1" rel="noopener noreferrer"&gt;Clean Code by Robert C. Martin&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fese3d47xxt958kxm4vx0.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fese3d47xxt958kxm4vx0.jpg" alt="book2" width="800" height="1060"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Clean code is a tricky subject. After a few years in development, you realize that there are certain standards that must be upheld in your code, but you also become aware that these same standards and best practices are not set in stone and may be broken on occasion. An example is the DRY principle. You may know that repeating code is bad practice, but would you stick to this rule so much, at the expense of readable code? That’s where Clean Code by Robert C. Martin saves the day. It dives into such questions and explains what it truly means for code to be clean.&lt;/p&gt;

&lt;p&gt;Robert’s book emphasizes that writing clean code isn’t about unbending rules, but about making thoughtful decisions in matters of readability, maintainability, and practicality.&lt;/p&gt;

&lt;p&gt;You’ll learn about writing code that is &lt;a href="https://www.docuwriter.ai/posts/ultimate-guide-self-documenting-code" rel="noopener noreferrer"&gt;self-documenting&lt;/a&gt;, keeping functions focused on one thing and other such rules for maintainable, readable and modular code. Rid yourself of code smells, and get a copy.&lt;/p&gt;

&lt;h4&gt;
  
  
  3. &lt;a href="https://www.amazon.com/Cracking-Coding-Interview-Programming-Questions/dp/0984782850/ref=sr_1_1?crid=2G5GEGENFI1FW&amp;amp;dib=eyJ2IjoiMSJ9.nj6XTCgbP7Ay4ig5zGU-o9OB8p-raRuETwl6G824MZwno93RxDTkpPMlKADkJwM_XWBpo9PWoT6eDDRBzPzJDV8VrJ_C7k4HDFz0cBvV0l3eMXG6q8dhBEhUDCiVAnx7293t3r7JngT1CFCtmu5fPuWJekgzMCwFNJQJU4NejqHFXpWeOOxteC3KorKgB7GX7waTgH_I9vdpxSRpAj2tAWZlmh_6p-JTp5nw78k-ZFc.ItkA6RSPjG5pM4lcfJEZ73W-velIx5yxE7UzfI2vGhE&amp;amp;dib_tag=se&amp;amp;keywords=cracking+the+coding+interview&amp;amp;qid=1774802584&amp;amp;s=books&amp;amp;sprefix=cracking+the+coding+inter%2Cstripbooks-intl-ship%2C360&amp;amp;sr=1-1" rel="noopener noreferrer"&gt;Cracking the Coding Interview by Gayle Laakmann McDowell&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq5z1qy2ufcj5ouu7t7ju.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq5z1qy2ufcj5ouu7t7ju.jpg" alt="book3" width="800" height="1143"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Coding interviews are not a walk in the park. In some cases, the questions you may face in a technical interview may seem quite abstract and sometimes a bit different from what you deal with at work in your day-to-day. If you’re thinking of taking a bold step into job searching, this book is a classic and a must-have in your preparation attempts.&lt;/p&gt;

&lt;p&gt;Beyond just practicing interview questions, it’ll help you build a problem-solving mindset. Solve over 180 coding questions and find yourself walking confidently in and out of technical interviews.&lt;/p&gt;

&lt;h4&gt;
  
  
  4. &lt;a href="https://www.amazon.com/Fundamentals-Software-Architecture-Engineering-Approach/dp/1098175514/ref=sr_1_1?crid=380NCLIK32RC9&amp;amp;dib=eyJ2IjoiMSJ9.aPA9gmJ_iYGRhv2bX2MYcxCGcgaFxdonRx9927J4MKuqj1aiXFXWxM-RvPctQ5rN-r4h_0shcPuBilCnfjqqad8RkKN6kX-Q8XxFyN_ny21a9eyiubebjXqvMPhgh-5D2_HQyImrq1dpZ_LF5ouEqCWkEtY3XCbTo2rP9qDp_AReADqD2wP3eoNL1OKQGqTC4ibWTsQ6PSkM0ja7hYHMv0Yw70GCyJ6FdaVdywxhcQw.MjkjR-jDh0dylF462_ViUwEqr3By-t9CSszYcx0fa0E&amp;amp;dib_tag=se&amp;amp;keywords=fundamentals+of+software+architecture&amp;amp;qid=1774802663&amp;amp;s=books&amp;amp;sprefix=fundamentals+of+software+architecture%2Cstripbooks-intl-ship%2C348&amp;amp;sr=1-1" rel="noopener noreferrer"&gt;Fundamentals of Software Architecture by Richard and Ford&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F04fjy9ylel10my79bfd4.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F04fjy9ylel10my79bfd4.jpg" alt="book 4" width="800" height="1050"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This book is a haven for those seeking a good introduction to Software Architecture fundamentals. It discusses eight architectural styles, each with detailed explanations. It explains how different architectural styles impact system performance, scalability, and maintainability, which are key concerns in backend development. It could serve as a great handbook and source material for all things architecture-related.&lt;/p&gt;

&lt;h4&gt;
  
  
  5. &lt;a href="https://www.amazon.com/Grokking-Algorithms-Second-Aditya-Bhargava/dp/1633438538/ref=sr_1_1?crid=1BO6JSEA1BHQN&amp;amp;dib=eyJ2IjoiMSJ9.udKCRwfqvqqXcW7DFKotFoK3jLzxS09orNAGvMOeslxdic8UqaMG0HL2Hy-C2vNtl9v6Fm1-Jf10NAQ1w1gsqa5xeX0T_xVbgL_eIy7iB9ud6rMrCFOmNz1qz_1HV-rWlcn9mkvHCsQ-L6UnhbLTrJeRq3sqpYB0UC-9REhTLwuOpexpo6aFFwOSlueTAyP05Joj4QTIqfzPgdURRQ7Vj46kWhxLAN1kotW90zwBynw.mv7FuyR3UUpezSTpXwGIVBjeA7agZeG_Zhpdg__Oolo&amp;amp;dib_tag=se&amp;amp;keywords=grokking+algorithms&amp;amp;qid=1774802724&amp;amp;s=books&amp;amp;sprefix=grokking+alg%2Cstripbooks-intl-ship%2C690&amp;amp;sr=1-1" rel="noopener noreferrer"&gt;Grokking Algorithms by Aditya Bhargava&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqd2c79rhk8ifmyrsabat.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqd2c79rhk8ifmyrsabat.jpg" alt="book5" width="800" height="1002"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This book is a delight. It makes algorithms easier to follow and visual learners would benefit greatly from the illustrations. In it, Aditya simplifies concepts like &lt;a href="https://dev.to/gr8soln/mastering-time-and-space-complexity-a-beginners-guide-to-big-o-notation-33ae"&gt;Big O Notation&lt;/a&gt;, recursion and dynamic programming.&lt;/p&gt;

&lt;p&gt;On reading this book, you’ll realize soon enough that it makes complex algorithmic concepts intuitive, helping developers understand not just how solutions work, but why they work. The author makes these rather abstract concepts easier to mentally navigate with his witty and brilliant writing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;The above are just a few of many interesting and amazing books that will keep you deeply engaged. While some of the books on this list aren’t specifically targeted at backend developers, they are great to have in your library as they concern general coding best practices and critical thinking.&lt;/p&gt;

&lt;p&gt;Why not pick up a book today? Perhaps lose yourself in the whimsical world of Grokking Algorithms, be amazed by how Martin Kleppman explains the secret recipes needed in designing data-intensive applications, or carefully observe and craft your methods after reading Robert C. Martin’s Clean Code.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Have a great one!!!&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Author: &lt;a href="https://blog.masteringbackend.com/authors/lonercode" rel="noopener noreferrer"&gt;Amanda Ene Adoyi&lt;/a&gt;
&lt;/h3&gt;




&lt;h3&gt;
  
  
  Thank you for being a part of the community
&lt;/h3&gt;

&lt;p&gt;Before you go:&lt;/p&gt;

&lt;h3&gt;
  
  
  Whenever you’re ready
&lt;/h3&gt;

&lt;p&gt;There are 4 ways we can help you become a great backend engineer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://masteringbackend.com/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;The MB Platform:&lt;/strong&gt;&lt;/a&gt; Join thousands of backend engineers learning backend engineering. Build real-world backend projects, learn from expert-vetted courses and roadmaps, track your learning and set schedules, and solve backend engineering tasks, exercises, and challenges.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://masteringbackend.com/academy?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;The MB Academy:&lt;/strong&gt;&lt;/a&gt; The “MB Academy” is a 6-month intensive Advanced Backend Engineering Boot Camp to produce great backend engineers.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://backendweeky.dev/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;Join Backend Weekly:&lt;/strong&gt;&lt;/a&gt; If you like posts like this, you will absolutely enjoy our exclusive weekly newsletter, sharing exclusive backend engineering resources to help you become a great Backend Engineer.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://getbackendjobs.com/?ref=medium" rel="noopener noreferrer"&gt;&lt;strong&gt;Get Backend Jobs:&lt;/strong&gt;&lt;/a&gt; Find over 2,000+ Tailored International Remote Backend Jobs or Reach 50,000+ backend engineers on the #1 Backend Engineering Job Board.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Originally published at&lt;/em&gt; &lt;a href="https://blog.masteringbackend.com/top-5-books-every-backend-developer-should-read" rel="noopener noreferrer"&gt;&lt;em&gt;https://blog.masteringbackend.com&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;




</description>
      <category>reading</category>
      <category>backenddeveloper</category>
      <category>backend</category>
      <category>booksrecommendation</category>
    </item>
  </channel>
</rss>
