🎯 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 Task record 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
  • @RestControllerAdvice returning consistent JSON error shapes
  • application-dev.properties / application-prod.properties profile separation
💼 Capstone pattern: Every Spring Boot micro-service you build professionally follows this same skeleton. Mastering this mini build means you can scaffold any domain — payments, inventory, user management — in under an hour.

🏗️ Real-world scenario

🏗️
NairaSwift · Lagos, Nigeria
Arc D capstone — everything wired together

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

Lesson 19
@SpringBootApplication
Entry point & auto-config
Lesson 20
@RestController
HTTP routes & JSON serialisation
Lesson 21
@Service
Business logic + DI
Lesson 22
DTOs + @Valid
Input validation
Lesson 23
@RestControllerAdvice
Uniform error responses
Lesson 24
Config Profiles
dev/prod properties
Lesson 25
Spring Security
Auth & authorisation

📦 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.

mvn spring-boot:run
Task.java + DTOsLesson 26 · domain model, CreateTaskRequest, UpdateStatusRequest
verified output — server started
:: Spring Boot :: (v3.3.5) Started NairaswiftApplication in 0.851 seconds (process running for 0.961)

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.

curl -s -u samuel:pass123 -X POST http://localhost:8765/api/tasks -H "Content-Type: application/json" -d '{"title":"KYC review — Emeka Obi","assignedTo":"samuel"}'
TaskController.javaLesson 26 · GET (filter), POST, PATCH, DELETE
verified output — POST /api/tasks
{ "id": 1, "title": "KYC review — Emeka Obi", "assignedTo": "samuel", "status": "OPEN", "createdAt": "2026-04-26T20:45:00.000000" }
Verb + PathAnnotationSuccess statusAuth required
GET /api/tasks@GetMapping200AGENT
GET /api/tasks?status=OPEN@RequestParam200AGENT
POST /api/tasks@PostMapping + @Valid201AGENT
PATCH /api/tasks/{id}/status@PatchMapping + @Valid200AGENT
DELETE /api/tasks/{id}@DeleteMapping204AGENT

🔗 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.

curl -s -u samuel:pass123 http://localhost:8765/api/transfers
RequestLifecycle.javaLesson 26 · all Arc D pieces working together
verified output — full transfer list (wired system)
[ { "id": 1001, "fromAccount": "NS-100001", "toAccount": "NS-100002", "amountNgn": 25000.0, "currency": "NGN", "status": "COMPLETED", "createdAt": "2026-04-26T18:37:23.205336" }, { "id": 1002, "fromAccount": "NS-100003", "toAccount": "NS-100004", "amountNgn": 150000.0, "currency": "NGN", "status": "COMPLETED", "createdAt": "2026-04-26T20:07:23.205359" } ]

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

EasyWhat is the role of each Arc D annotation?
+

@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.

EasyWhy use @PatchMapping instead of @PostMapping for status updates?
+

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.

MediumHow would you add pagination to the GET /api/tasks endpoint?
+

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.

MediumHow would you persist tasks to a database instead of an in-memory Map?
+

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.

HardHow would you add request tracing so every log line includes a unique trace ID?
+

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

Question 1 of 5
Which annotation combination creates a validated REST endpoint?
Question 2 of 5
What does @PatchMapping do differently from @PutMapping?
Question 3 of 5
How do you filter a list by a query parameter in Spring MVC?
Question 4 of 5
Which is the correct HTTP status for "resource created successfully"?
Question 5 of 5
What is the purpose of @RestControllerAdvice in this mini build?
0
/ 5
Arc D complete!

Next up: Arc E — JDBC & Database Fundamentals →

⚠️ Common mistakes

State in a controller field
A @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.
Missing @Valid on @PatchMapping body
Forgetting @Valid on @RequestBody UpdateStatusRequest means the @Pattern constraint is never checked and invalid statuses silently pass through.
Using @PostMapping for updates
POSTing to /tasks/1/status creates ambiguity. Use @PatchMapping for partial updates and @PutMapping for full replacements. REST verbs carry semantic meaning.
No Location header on 201 Created
Best practice for POST-create is to include a 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
Africa & India's Best AI Academy
🤖 AI-first 🎓 Placement Assistance

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 →