APIs
REST modeling: multiple-choice review
Six questions that cut across the whole unit. Each one is a design decision you make at a whiteboard or in a PR review — not a definition to recite, but a tradeoff to defend when a teammate pushes back.
Confirm you can connect resource modeling, non-CRUD transitions, nesting depth, the representation/resource split, idempotency, and HATEOAS pragmatics — the synthesis the lesson built toward.
A teammate proposes GET /getOpenOrders and POST /createOrder as your two new endpoints. What is the most precise objection?
You must expose 'cancel an order', a guarded transition with rules (not shipped, not already cancelled). Which model is both RESTful enough and safe?
A dashboard renders /customers/7/projects/3/orders/42/items in nine sequential calls and the path breaks whenever an item moves between orders. What is the senior fix?
Your API serializes ORM rows straight to JSON. Why is adding an explicit mapping layer (DTO/serializer) the highest-leverage decision in the design?
A client retries POST /payments because the response timed out, and the customer is charged twice. Which statement about idempotency is correct?
A purist blocks your PR because the responses do not carry hypermedia links (HATEOAS). How should a senior weigh this?
The through-line: a REST API models nouns the client needs, with the verb in the HTTP method, filtering and paging in query params, and non-CRUD transitions as guarded action or transition resources — never a client-writable status field. Keep nesting shallow and use expansion to kill chatty screens. Serialize through a mapping layer so the representation is a contract you own, not your DB schema. Know that POST is not idempotent (use idempotency keys for safe retries) and that HATEOAS is the elegant theory level-2 REST rarely needs.