Spring Boot Tutorial 0/110 lessons ~6 min read Lesson 102

    REST API Challenges

    API design skill shows up when constraints collide: idempotency, pagination, signed uploads, bulk results, and webhook retries.

    Course progress0%
    Focus
    12 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    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

    1. Pick one scenario; write OpenAPI 3 paths, schemas, and error responses.
    2. List idempotency and pagination rules in the description.
    3. Generate or hand-write Boot 3 controller interfaces + DTOs (jakarta.validation).
    4. Add problem-details for 4xx/5xx; peer-review the spec before implementing persistence.

    Informative example

    Idempotent booking confirm (contract excerpt).

    java
    POST /api/reservations/{id}/confirm
    Headers:
    Idempotency-Key: 8f3c... (required)
    Authorization: Bearer <token>
    Responses:
    200 application/json ReservationConfirmed
    409 application/problem+json already_cancelled
    422 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.

    3 questions
    1BeginnerQuestionWhy require Idempotency-Key on confirm?+

    Answer

    Client retries after timeouts must not create duplicate reservations or charges.
    2IntermediateQuestionHow should bulk APIs report partial failure?+

    Answer

    Per-row status in the response body with a multi-status or 200 + embedded errors — never a silent partial success.
    3IntermediateQuestionWhat belongs in a webhook signature?+

    Answer

    HMAC over timestamp + body with a shared secret, plus rejection of stale timestamps.

    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.

    Ready to mark this lesson complete?Track your journey across the entire course.