Api Design easy
A client wants to update only the 'status' field of an order, leaving other fields unchanged. Which HTTP method is most appropriate?
- A PUT /orders/123 with the new status and all other existing fields.
- B PATCH /orders/123 with a JSON body containing only { "status": "shipped" }.
- C POST /orders/123/status with the value "shipped".
- D GET /orders/123?status=shipped to trigger the update.
Answer: B. PATCH /orders/123 with a JSON body containing only { "status": "shipped" }.
The PATCH method is designed specifically for partial updates, allowing you to send only the fields that need to be changed (e.g., just the status). PUT, in contrast, requires sending the entire resource representation to replace the existing one. Using PATCH reduces network payload size and prevents accidental overwriting of other fields if the client has stale data.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- You're designing a REST API for a blog. Which endpoint best represents 'get all comments for post 123'?
- A client calls POST /users with valid data, and the user is created. What status code should the server return?
- A client retries a failed 'POST /payments' request due to network timeout. The server receives the request twice. Without idempotency handling, what can happen?
- An API returns 10,000 products. Returning all in one response is impractical. Which pagination approach is simple and stateless?
- Your API serves both mobile apps and third-party integrations. Which authentication method is most appropriate?
- Service A calls Service B, which is failing. Without protection, A keeps sending requests, cascading the failure. What pattern prevents this?