🎯 What you will build
This lesson is the Arc D capstone. Rather than learning a new concept, you wire together every technique from Lessons 19–25 into a single cohesive application: a Task Management API for NairaSwift's back-office team. By the end you will have a running Spring Boot service with:
- A
Taskrecord domain model and validated DTOs (CreateTaskRequest,UpdateStatusRequest) - Full CRUD in a
@RestController: GET (with filtering), POST (201 Created), PATCH, DELETE - Spring Security gating every endpoint with HTTP Basic + AGENT role
@RestControllerAdvicereturning consistent JSON error shapesapplication-dev.properties/application-prod.propertiesprofile separation
🏗️ Real-world scenario
Samuel's team ships a Task API for NairaSwift's back-office: agents create tasks (KYC check, transfer review, account freeze), mark them complete, and list open items. The API combines every technique from Arc D: validated DTOs, @RestControllerAdvice error handling, Spring Security, and dev/prod config profiles.
Arc D techniques recap
📦 Task model + DTOs
The Task record is the domain object — immutable, self-describing. Two DTOs handle input: CreateTaskRequest carries the creation payload; UpdateStatusRequest carries only the status field for PATCH. Constraints are declared at the field level with Jakarta Validation annotations.
Records as DTOs: Java records (Java 16+) are ideal for DTOs — they are immutable, auto-generate equals, hashCode, and toString, and declare all fields in the compact constructor header. No boilerplate getters needed; Jackson serialises them out of the box.
🎮 TaskController — full CRUD
The controller is thin: it delegates to the in-memory store (a LinkedHashMap for ordered iteration), validates inputs with @Valid, and returns the correct HTTP status codes — 201 for creation, 204 for deletion, 404 when a task is not found.
| Verb + Path | Annotation | Success status | Auth required |
|---|---|---|---|
GET /api/tasks | @GetMapping | 200 | AGENT |
GET /api/tasks?status=OPEN | @RequestParam | 200 | AGENT |
POST /api/tasks | @PostMapping + @Valid | 201 | AGENT |
PATCH /api/tasks/{id}/status | @PatchMapping + @Valid | 200 | AGENT |
DELETE /api/tasks/{id} | @DeleteMapping | 204 | AGENT |
🔗 Arc D — request lifecycle
Every HTTP request to the Task API passes through seven layers. Understanding this flow is critical for debugging and for answering "what happens when a request arrives?" in interviews.
The power of the stack: Spring Security sits outside the DispatcherServlet — it intercepts requests before routing even begins. This means a 401/403 response never reaches your controller. Validation (400) and business errors (404) are handled inside the controller layer by @RestControllerAdvice.
🎤 Interview Q&A
@SpringBootApplication: bootstraps context and auto-config. @RestController: HTTP binding + JSON. @Service: business logic bean. @Valid: triggers constraint validation. @RestControllerAdvice: global error handler. @Bean: manual bean registration. Each has a single, clear responsibility.
PATCH is semantically "partial update" — the client sends only the field being changed (status). POST means "create a new resource." Using the right verb makes the API self-documenting and aligns with REST conventions.
Accept @RequestParam int page, int size parameters. Use stream skip/limit: stream.skip((long) page * size).limit(size).toList(). Spring Data JPA (Lesson 28) provides Pageable out of the box for database-backed APIs.
Replace the Map with a JPA repository (Lesson 27–29): annotate Task with @Entity, add @Id @GeneratedValue, create a TaskRepository extends JpaRepository<Task, Long>, and inject it into the controller/service. Spring Data JPA provides findAll, findById, save, deleteById automatically.
Use MDC (Mapped Diagnostic Context). Write a OncePerRequestFilter: generate UUID traceId = UUID.randomUUID().toString(), call MDC.put("traceId", traceId), chain the request, finally MDC.remove("traceId"). Configure the log pattern to include %X{traceId}. Every log line within the request thread will include the ID.
📝 Quiz — 5 questions
Next up: Arc E — JDBC & Database Fundamentals →
⚠️ Common mistakes
@RestController is a singleton. The Map<Long, Task> store in the controller works only for demos; in production concurrent requests corrupt it. Move it to @Service; ultimately replace with a database.@Valid on @RequestBody UpdateStatusRequest means the @Pattern constraint is never checked and invalid statuses silently pass through./tasks/1/status creates ambiguity. Use @PatchMapping for partial updates and @PutMapping for full replacements. REST verbs carry semantic meaning.Location: /api/tasks/1 header so clients can fetch the new resource without guessing the URL. Add .header("Location", "/api/tasks/" + task.id()) to the ResponseEntity builder.✅ Key takeaways
- A complete Spring Boot REST API needs: controller + service + DTO + validation + error handler + security + config
- @PatchMapping + @Valid + ResponseEntity = clean partial-update endpoint
- SecurityFilterChain gates every request before it reaches the controller
- Use @RequestParam for optional filtering; @PathVariable for resource identity
- This mini build is the template for every Spring Boot micro-service you will write
From Task API to a deployed Spring Boot AI service
Join the Best AI Programs — three 5-month courses, fully online, with placement assistance. Week 1 is free.
Explore our AI-era courses →