Lesson 49: Building a REST API with Spring Boot

19 Aug 2026 1 min Swarnil Singhai

REST APIs expose resources over HTTP verbs (GET/POST/PUT/DELETE) — Spring Boot maps these directly to annotated controller methods.

Real-time example

A simple product catalog API lets a frontend list, create, and delete products entirely over HTTP, decoupled from any specific UI.

@RestController
@RequestMapping("/products")
class ProductController {
    private final ProductService service;
    ProductController(ProductService service) { this.service = service; }

    @GetMapping
    List<Product> list() { return service.findAll(); }

    @PostMapping
    Product create(@RequestBody Product p) { return service.save(p); }

    @DeleteMapping("/{id}")
    void delete(@PathVariable String id) { service.delete(id); }
}

What's happening

@RequestBody deserializes incoming JSON into a Product automatically; Spring serializes the return value back to JSON.

Keep controllers thin — they should translate HTTP to service calls, not contain business logic themselves.

Advertisement