Skip to content
Ameen Abozaid
Planned lessonJNR-013-L02

Controllers: the HTTP edge

  • Lesson 2 of 8
  • Junior
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.
  • @RestController returns data (JSON), not pages.
Draft outline details

Demonstration

java
@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.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.