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

Concept

Request validation

Bean Validation annotations on request classes, @NotBlank, @Size, @Email, with @Valid on the parameter, reject bad input before your code runs. The errors come back as a 400 with field details.

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 what Bean Validation annotations check and when
  2. Annotate a request record and add @Valid to the parameter
  3. Spot the missing @Valid that lets invalid input through

In practice

A few lines that show Request validation doing its job.

Java
public record CreateOrder(
    @NotEmpty List<@Valid LineItem> items,
    @Email String customerEmail,
    @Size(max = 200) String note
) {}

public record LineItem(@NotBlank String sku, @Min(1) @Max(99) int quantity) {}

@PostMapping
OrderView create(@RequestBody @Valid CreateOrder request) { ... }

The common mistake

Watch for

Annotating the record but forgetting @Valid on the controller parameter, or on a nested list element. Nothing is checked and the invalid request reaches your service.

What to know first

Your roadmap puts these before Request validation, unless you already know them.

How it stays learned

Once a session shows you understand Request validation, 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
Previous in the module← Controllers and mappings