REST API Challenges
API design skill shows up when constraints collide: idempotency, pagination, signed uploads, bulk results, and webhook retries.
Introduction
API design skill shows up when constraints collide: idempotency, pagination, signed uploads, bulk results, and webhook retries. These TechLearningPRO challenges force you to write the OpenAPI contract first, then implement on Spring Boot 3 / Java 21.
Each scenario includes required endpoints, status codes, and failure modes. Spec-first keeps interviews and production RFCs honest.
No fluff — deliver OpenAPI + a Boot controller skeleton that compiles.
Purpose of this lesson
Design and stub production-grade REST APIs for booking, file sharing, webhooks, and bulk ops with explicit OpenAPI contracts.
Understanding the topic
Four scenarios — OpenAPI first, then Boot 3 stubs.
- Hotel booking — rooms, availability, reservations, idempotent confirm.
- File sharing — signed upload URLs, per-link expiry, download authz.
- Webhook delivery — signed payloads, retries, re-drive endpoint.
- Bulk create — 1 000 rows in one request with per-row results.
Step-by-step explanation
- Pick one scenario; write OpenAPI 3 paths, schemas, and error responses.
- List idempotency and pagination rules in the description.
- Generate or hand-write Boot 3 controller interfaces + DTOs (
jakarta.validation). - Add problem-details for 4xx/5xx; peer-review the spec before implementing persistence.
Informative example
Idempotent booking confirm (contract excerpt).
POST /api/reservations/{id}/confirmHeaders:Idempotency-Key: 8f3c... (required)Authorization: Bearer <token>Responses:200 application/json ReservationConfirmed409 application/problem+json already_cancelled422 application/problem+json payment_failed// Boot 3 controller stub@RestController@RequestMapping("/api/reservations")class ReservationController {@PostMapping("/{id}/confirm")ResponseEntity<ReservationConfirmed> confirm(@PathVariable UUID id,@RequestHeader("Idempotency-Key") String idemKey) {return ResponseEntity.ok(service.confirm(id, idemKey));}}
Real-world use
TechLearningPRO partner onboarding once double-charged a sandbox reservation because confirm lacked an idempotency key. Adding the header and a uniqueness constraint on (partner_id, idem_key) stopped the duplicate — exactly what this booking challenge drills.
Security implications
REST design is also abuse design.
- Signed upload URLs expire; never embed long-lived credentials in client apps.
- Webhook signatures use HMAC with a rotated secret from a secret manager.
- Bulk endpoints need stricter auth and rate limits than single-row creates.
Best practices
- Problem Details (RFC 7807) for errors.
- Cursor pagination for lists that can grow.
- Document rate limits in the OpenAPI description.
Common mistakes
- Implementing before the status/error matrix is agreed.
- Returning 200 for partial bulk failures without per-row errors.
- Unsigned webhooks that anyone can forge.
Advanced interview questions
Interview Prep
Practice concise answers, then expand each card for the explanation.
1BeginnerQuestionWhy require Idempotency-Key on confirm?+
Answer
2IntermediateQuestionHow should bulk APIs report partial failure?+
Answer
3IntermediateQuestionWhat belongs in a webhook signature?+
Answer
Hands-on exercise
Challenges (do all four specs; implement at least one).
1) Booking API OpenAPI with availability search + idempotent confirm.
2) File-sharing API with POST /uploads/sign returning URL + expiry.
3) Webhooks: POST /webhooks/endpoints, delivery log, POST /deliveries/{id}/redrive.
4) Bulk: POST /api/items:batchCreate returning {results:[{index,status,id|error}]}.
Deliverables: openapi.yaml + Boot 3 stub module + 10 curl examples.
Summary
REST challenges harden your contract skills. Next: practise diagnosing production failures.