← Spring Boot learning path
Spring Boot · Module 3 of 10

Building REST controllers

Create JSON APIs with @RestController.

📖 Key ideas

  1. @RestController + @GetMapping("/api/users") returns JSON.
  2. @PathVariable reads /users/{id}; @RequestParam reads ?q=.
  3. @RequestBody maps JSON to a Java object.
  4. ResponseEntity sets status and headers.
  5. Jackson converts objects to/from JSON automatically.
💡 Real-life example: A controller is a front desk clerk: takes requests, calls the right department (service), returns the answer.
@RestControllerController returning JSON
@GetMappingMaps GET requests
@PathVariableReads path values
ResponseEntityResponse with status and body