Api Design easy
A client POST /users with { email: 'not-an-email', age: -5 }. The server validates and rejects. What status code is structurally and semantically correct?
- A 400 Bad Request
- B 422 Unprocessable Entity
- C 403 Forbidden
- D 409 Conflict
Answer: B. 422 Unprocessable Entity
While 400 Bad Request is commonly used, **422 Unprocessable Entity** is the most semantically accurate status code for validation errors where the request syntax is correct (valid JSON) but the instructions cannot be followed (e.g., invalid email format). It clearly distinguishes logic/validation errors from malformed requests.
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 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?