Computer Science A
Learning Goals 3
Learning Goals 3
Learning Goals 3
Learning Goals 3
Learning Goals 3
Learning Goals 3
Learning Goals 4
Learning Goals 3
Learning Goals 4
API Controller
REST API Controller
Use a REST controller only for the GitHub Pages path in Java Spring Hacks.
@RestControllerreturns response data as JSON.@RequestMapping("/api/data")gives this controller an/api/*prefix.@GetMapping,@PostMapping,@PutMapping, and@DeleteMappingdefine HTTP operations.ResponseEntity<T>combines a typed response body with an HTTP status.
@RestController
@RequestMapping("/api/data")
public class DataApiController {
private final DataRepository repository;
public DataApiController(DataRepository repository) {
this.repository = repository;
}
@GetMapping
public ResponseEntity<List<Data>> getAll() {
return ResponseEntity.ok(repository.findAll());
}
}
The /api/* filter chain is configured in SecurityConfig.java with Order(1). It is stateless and must allow the GitHub Pages origin through CORS. For server-rendered HTML and forms, use the separate /mvc/* path instead.
Course Timeline
Week 0 Chat click to open
No messages yet.
Week 1 Chat click to open
No messages yet.
Week 2 Chat click to open
No messages yet.
Week 3 Chat click to open
No messages yet.
Week 4 Chat click to open
No messages yet.
Week 5 Chat click to open
No messages yet.
Week 6 Chat click to open
No messages yet.
Week 13 Chat click to open
No messages yet.
Week 17 Chat click to open
No messages yet.
Week 18 Chat click to open
No messages yet.
Week 19 Chat click to open
No messages yet.
Week 21 Chat click to open
No messages yet.
Week 22 Chat click to open
No messages yet.
Week 25 Chat click to open
No messages yet.
Week 27 Chat click to open
No messages yet.
Week 31 Chat click to open
No messages yet.
Week 34 Chat click to open
No messages yet.