API design · Design
Designing the orders endpoints
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voiceThe interviewer asks
Design the REST endpoints for orders in a food-delivery app: create an order, list my orders, get one, cancel one, and rate one. Which methods, URLs and status codes?
Then
Follow-ups the interviewer asks next
- PUT vs PATCH vs POST: which are idempotent?
- Is "cancel" a DELETE?
- Which status code when the order is already delivered and can't be cancelled?
- 401 vs 403? 400 vs 422?
- How do you answer when creating something takes a while?
The answer
What a strong answer covers
- Plural nouns, no verbs in paths:
POST /orders→ 201 with aLocationheader;GET /orders?status=…&cursor=…for the signed-in user (identity from the token, never from a query parameter);GET /orders/{id}→ 404 if it isn't theirs. - Cancel is a state change, not a deletion:
POST /orders/{id}/cancelorPATCH /orders/{id}with{ "status": "cancelled" }. The order still exists. - Rating: one per order, so
PUT /orders/{id}/ratingis natural and idempotent. - Idempotent methods: GET, PUT, DELETE (and HEAD, OPTIONS). POST and PATCH are not by default.
- Status codes: 200, 201, 202 (accepted, still processing), 204, 400 (malformed), 401 (not signed in), 403 (signed in but not allowed), 404, 409 (conflict, such as already delivered) or 422 (valid JSON but breaks a rule), 429, 5xx for server faults.
- Also: pagination, filtering, one error shape, versioning.
The red pen
Common traps
Avoid:/getOrders; 200 with { success: false }; DELETE for cancel; taking the user id from the request body.
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voicePractise questions like this out loud
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.