Building REST APIs in Spring Boot relies on a small set of core annotations that define controllers, map HTTP requests, and bind request data to method parameters.
A ProductController annotated with @RestController exposes GET /products/{id} using @GetMapping and @PathVariable to fetch a single product, and POST /products using @PostMapping and @RequestBody to create one from a JSON payload.
@RestController
@RequestMapping("/products")
public class ProductController {
@GetMapping("/{id}")
public Product getProduct(@PathVariable Long id) {
return productService.findById(id);
}
@PostMapping
public Product createProduct(@RequestBody Product product) {
return productService.save(product);
}
}A concise interview answer is
The core ones I reach for are @RestController to mark the class, @RequestMapping or its shortcuts like @GetMapping and @PostMapping to map HTTP requests, @PathVariable to bind URI segments, and @RequestBody to deserialize the JSON payload into a Java object. Together they cover most of what a typical REST endpoint needs.
Last updated: 11 November 2026
Next question: Have you seen real-world bugs caused by choosing PUT instead of POST (or the reverse)? How were they fixed?