Api Design medium
A client calls GET /orders/123 and needs the customer object embedded. The API supports field expansion. How is this requested?
- A Include a query parameter such as ?expand=customer or ?include=customer to tell the server to inline the related resource object.
- B Use a hierarchical URL structure like /orders/123/customer to explicitly request the sub-resource as a standalone representation.
- C Configure the server's default serialization settings to always include all nested relationships within every GET request for the resource.
- D Define a custom media type in the Accept header that signals the server to return a 'verbose' version of the response with all fields populated.
Answer: A. Include a query parameter such as ?expand=customer or ?include=customer to tell the server to inline the related resource object.
**Field expansion** allows clients to request nested resources within the main response to avoid additional round trips (the N+1 problem on the client side). A common convention is a query parameter like `?expand=customer` (used by Stripe) or `?include=comments` (used by JSON:API). This keeps the response lean by default while offering flexibility.
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?