REST API Controllers
Building REST Endpoints
Create RESTful services with @RestController annotations.
Controller Pattern
@RestController
@RequestMapping("/api/products")
public class ProductController {
@GetMapping public List getAll() { }
@GetMapping("/{id}") public Product getOne() { }
@PostMapping public Product create() { }
@PutMapping("/{id}") public Product update() { }
@DeleteMapping("/{id}") public void delete() { }
}Best Practices
- ResponseEntity for status codes
- @Valid for request validation
- Exception handling with @ControllerAdvice
- HATEOAS links