1. Concept library
  2. Java & Spring Boot
  3. Module 7: REST APIs

Concept

Controllers and mappings

A @RestController maps HTTP requests to methods with @GetMapping, @PostMapping and friends, and turns return values into JSON. Path variables, query parameters and the body arrive as method arguments.

What a session covers

The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.

  1. Explain how a request reaches a controller method and its arguments
  2. Write endpoints with path variables, query parameters and a body
  3. Spot the JPA entity returned straight from a controller

In practice

A few lines that show Controllers and mappings doing its job.

Java
@RestController
@RequestMapping("/api/orders")
public class OrderController {
    private final OrderService orders;
    OrderController(OrderService orders) { this.orders = orders; }

    @GetMapping("/{id}")
    OrderView get(@PathVariable UUID id) { return orders.get(id); }

    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    OrderView create(@RequestBody @Valid CreateOrder request) { return orders.create(request); }
}

The common mistake

Watch for

Returning JPA entities straight from controllers. Lazy relationships serialise unpredictably, every schema change becomes an API change, and fields you never meant to expose leak out.

What to know first

Your roadmap puts these before Controllers and mappings, unless you already know them.

How it stays learned

Once a session shows you understand Controllers and mappings, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.

  1. Day 3First recall, while it is fresh
  2. Day 7Second, a week on
  3. Day 18Last, when it has settled

Where it leads

Topics that build on Controllers and mappings.

Next in the moduleRequest validation →