Controllers: the HTTP edge
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
write a thin controller.
Planned topics
- A controller translates HTTP to a method call and the result back to HTTP.
- It handles paths, methods, status codes, and request/response bodies.
- It contains no business rules and no database code.
@RestControllerreturns data (JSON), not pages.
Draft outline details
Demonstration
@RestController
@RequestMapping("/products")
class ProductController {
private final ProductService service;
ProductController(ProductService service) { this.service = service; }
@GetMapping("/{id}")
ProductResponse get(@PathVariable long id) { return service.get(id); }
}Check your understanding
Where does "a discount cannot exceed 50%" go?
Show answer
In the service, not the controller.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.