← Spring Boot learning pathSpring Boot · Module 3 of 10
Building REST controllers
Create JSON APIs with @RestController.
📖 Key ideas
- @RestController + @GetMapping("/api/users") returns JSON.
- @PathVariable reads /users/{id}; @RequestParam reads ?q=.
- @RequestBody maps JSON to a Java object.
- ResponseEntity sets status and headers.
- 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