Api Design easy
A client wants the response in XML instead of JSON. How should it indicate this?
- A Send the request to a format-specific endpoint like /api/xml/users.
- B Include the Accept: application/xml header in the request.
- C Include the Content-Type: application/xml header in the request.
- D Set a custom X-Response-Format: xml header.
Answer: B. Include the Accept: application/xml header in the request.
The `Accept` header is the HTTP standard mechanism for **Content Negotiation**. It allows the client to specify the media types it can understand (e.g., `application/xml` or `application/json`). The server then responds with the best available format. While query parameters or file extensions are sometimes used, the `Accept` header is the semantically correct approach defined in the HTTP specification.
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?