Api Design easy
A client calls POST /users with valid data, and the user is created. What status code should the server return?
- A 200 OK - indicating the server received the data.
- B 201 Created - indicating a new resource was successfully created.
- C 202 Accepted - indicating the request is queued for processing.
- D 204 No Content - indicating success without a response body.
Answer: B. 201 Created - indicating a new resource was successfully created.
The 201 Created status code specifically indicates that a request has been fulfilled and has resulted in one or more new resources being created. The response ideally includes a 'Location' header pointing to the newly created resource. While 200 OK is valid for general success, 201 provides more specific semantic meaning for creation events.
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 wants to update only the 'status' field of an order, leaving other fields unchanged. Which HTTP method is most appropriate?
- 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?