@PathVariable binds a controller method parameter to a variable embedded in the request path. For a controller rooted at /api/tacos, the route /api/tacos/{id} captures the actual path value and supplies it to the id parameter. section 7.1.1
Fetch a taco by ID
@GetMapping("/{id}") public ResponseEntity<Taco> tacoById(@PathVariable("id") Long id) { Optional<Taco> optTaco = tacoRepo.findById(id); if (optTaco.isPresent()) { return new ResponseEntity<>(optTaco.get(), HttpStatus.OK); } return new ResponseEntity<>(null, HttpStatus.NOT_FOUND); } A request to GET /api/tacos/4 passes 4 to id, which the repository uses to find the Taco. ResponseEntity lets the endpoint return 200 when found and 404 when no matching taco exists. section 7.1.1
