API Design Junior cheat sheet: interview answers

Every question of this level with its correct answer and explanation, on one page for a quick review before the interview.

  1. 1. What is a REST API, in practical terms?

    Correct answer: An HTTP API built around resources

    REST is an architectural style described by Roy Fielding. Most 'REST APIs' follow its main ideas: resources, uniform interface, statelessness and cacheability.

  2. 2. Which URL design follows common REST conventions?

    Correct answer: GET /users/42/orders

    URLs name resources (nouns, usually plural); the HTTP method says what to do. Verbs in paths are an RPC style.

  3. 3. What does 'stateless' mean for a REST API?

    Correct answer: Each request carries all that the server needs

    Statelessness makes horizontal scaling easy: any instance can handle any request.

  4. 4. Which HTTP method should create a new resource in a collection, like a new order?

    Correct answer: POST /orders

    The server assigns the ID and usually responds with 201 Created and a Location header pointing to the new resource.

  5. 5. What's the difference between PUT and PATCH?

    Correct answer: PUT replaces the resource; PATCH changes part of it

    With PUT, missing fields mean 'remove or reset'. PATCH changes only what's sent, e.g. using JSON Merge Patch.

  6. 6. Which HTTP methods are 'safe'?

    Correct answer: GET, HEAD, OPTIONS

    Safe methods don't change server state, so browsers, crawlers and caches may call them freely. Never change data in a GET handler.

  7. 7. Which methods are idempotent by HTTP semantics?

    Correct answer: GET, PUT, DELETE

    Repeating an idempotent request has the same effect as sending it once, so clients can retry after a timeout.

  8. 8. What should DELETE /orders/42 return if the order was deleted and there's nothing to send back?

    Correct answer: 204 No Content

    200 OK with a body is also fine if you return something. A repeated delete may return 404 or 204; document the choice.

  9. 9. What does the Location header in a 201 Created response contain?

    Correct answer: The URL of the newly created resource

    Clients can follow it to fetch the new resource. Many APIs also return the created object in the body.

  10. 10. Why should resource names in URLs usually be plural nouns, like /users?

    Correct answer: It reads the same for the collection and for items

    The exact convention matters less than consistency across the whole API. Style guides help teams agree.

  11. 11. What does 400 Bad Request mean?

    Correct answer: The request is malformed or invalid

    Some APIs use 422 Unprocessable Content for well-formed requests with invalid values. Either way, explain what's wrong in the body.

  12. 12. What's the difference between 401 Unauthorized and 403 Forbidden?

    Correct answer: 401: bad credentials; 403: not allowed to do this

    Despite its name, 401 is about authentication. Some APIs return 404 instead of 403 to avoid revealing that a resource exists.

  13. 13. Which status code fits 'email is already registered' when creating a user?

    Correct answer: 409 Conflict

    409 means the request conflicts with the current state of the resource. Include a clear error code in the body.

  14. 14. What does 429 Too Many Requests tell the client?

    Correct answer: It hit a rate limit and should slow down

    Defined in RFC 6585. Well-behaved clients back off instead of retrying immediately.

  15. 15. When should an API return 5xx codes?

    Correct answer: When the failure is on the server side

    Clients and monitoring treat 4xx as client errors and 5xx as server errors. Returning 200 with an error body hides failures from both.

  16. 16. What does 503 Service Unavailable usually mean?

    Correct answer: The server temporarily can't handle requests

    It's a retryable error, unlike most 4xx. Load balancers also return 503 when no healthy instance is available.

  17. 17. Why is returning 200 OK with { "error": "not found" } a bad practice?

    Correct answer: Clients, caches and monitoring rely on status codes

    Use the right status code and a consistent error body.

  18. 18. What does 404 Not Found mean for GET /orders/999?

    Correct answer: No order with ID 999 is available to this client

    For empty collections, return 200 with an empty list, not 404.

  19. 19. What does the Content-Type: application/json request header tell the server?

    Correct answer: The body is JSON

    The Accept header tells the server which response formats the client wants. A server may reply 415 Unsupported Media Type for unexpected content types.

  20. 20. What is the Accept header for?

    Correct answer: The client states which response types it can handle

    This is content negotiation. If the server can't produce any acceptable format, it can answer 406 Not Acceptable.

  21. 21. How should dates and times be represented in a JSON API?

    Correct answer: As ISO 8601 strings with a time zone

    A standard, unambiguous format avoids time zone bugs. Pick one style and use it everywhere.

  22. 22. Why might an API return large numeric IDs as strings in JSON?

    Correct answer: JavaScript numbers lose precision above 2^53

    Twitter-style 64-bit IDs are a classic example. Clients shouldn't do math on IDs anyway.

  23. 23. Which field naming style should a JSON API use?

    Correct answer: One consistent style across the whole API

    camelCase matches JavaScript clients; snake_case is common too. Consistency is what matters.

  24. 24. Where should filtering and sorting options go in a REST request?

    Correct answer: In query parameters, e.g. GET /orders?status=paid&sort=-createdAt

    Query parameters keep the resource URL stable and are cacheable. GET bodies aren't reliably supported by clients and proxies.

  25. 25. What does a good error response body include?

    Correct answer: A stable code, a clear message and field details

    RFC 9457 Problem Details (type, title, status, detail, instance) is a standard format for this.

  26. 26. What is RFC 9457 (Problem Details)?

    Correct answer: A standard JSON format for HTTP API errors

    It replaced RFC 7807. The media type is application/problem+json, and you can add your own fields.

  27. 27. Why should list endpoints be paginated?

    Correct answer: Returning everything gets slow as data grows

    Set a default and a maximum page size so one request can't ask for millions of rows.

  28. 28. What's the difference between offset and cursor pagination?

    Correct answer: Offset uses page numbers; cursor uses a position token

    Cursors are stable and fast on large tables but don't allow jumping to page N. Offsets are simple and fine for small, slow-changing data.

  29. 29. Why should a pagination cursor be opaque to clients?

    Correct answer: So the server can change its format freely

    Clients should only pass back what they received, typically a Base64-encoded value.

  30. 30. How can an API tell clients there are more pages?

    Correct answer: With a nextCursor field or a Link header

    The Link header is defined in RFC 8288; GitHub's API uses it for pagination.

  31. 31. How is a bearer token usually sent to an API?

    Correct answer: In the Authorization: Bearer <token> header

    Tokens in URLs end up in logs, browser history and referrers. Headers are the standard place.

  32. 32. Why must APIs be served only over HTTPS?

    Correct answer: Tokens and personal data would travel in plain text

    Redirecting HTTP to HTTPS isn't enough for APIs: the first request already leaked credentials. Reject plain HTTP and use HSTS.

  33. 33. What is an API key typically used for?

    Correct answer: Identifying the calling app for quotas and access

    API keys identify clients but aren't user authentication. Keep them out of front-end code and rotate them when leaked.

  34. 34. What is OAuth 2.0 mainly about?

    Correct answer: Delegated access without sharing the user's password

    'Sign in with Google' uses OAuth 2.0 together with OpenID Connect. Public clients like SPAs should use the authorization code flow with PKCE.

  35. 35. What does CORS control?

    Correct answer: Whether a browser lets another origin read responses

    CORS is enforced by browsers only. It's not an authentication mechanism; curl and servers ignore it.

  36. 36. Why should an API validate all input even if the official client already does?

    Correct answer: Anyone can call the API directly with any data

    Validate types, ranges, formats and sizes, and reject unknown fields to avoid mass assignment.

  37. 37. What is OpenAPI?

    Correct answer: A standard format for describing HTTP APIs

    From an OpenAPI document you can render docs (Swagger UI, Redoc), generate clients and servers, and validate requests.

  38. 38. What's the benefit of a 'design-first' API approach?

    Correct answer: The contract is agreed on before implementation

    Mock servers built from the spec let front-end developers start early. Code-first works too, but changes are easier to miss.

  39. 39. Why should an API have a style guide?

    Correct answer: So all endpoints follow the same conventions

    Public guides from Google, Microsoft and Zalando are good starting points. Linters like Spectral can check OpenAPI documents against rules.

  40. 40. What is JSON Schema used for in APIs?

    Correct answer: Describing and validating the structure of JSON

    OpenAPI uses JSON Schema for its data models. Many frameworks validate requests directly against schemas.

  41. 41. Which change to an existing API response is usually backward compatible?

    Correct answer: Adding a new optional field

    Clients should ignore unknown fields. Removing, renaming or retyping fields breaks existing clients.

  42. 42. What is a common way to version a REST API?

    Correct answer: A version in the URL like /v1/orders

    URL versions are simple and visible; header or media type versions keep URLs stable. Avoid frequent major versions: evolve compatibly instead.

  43. 43. Why should clients ignore unknown fields in responses?

    Correct answer: So servers can add fields without breaking them

    This 'tolerant reader' principle is part of most API guidelines.

  44. 44. How should an API announce that an endpoint will be removed?

    Correct answer: Mark it deprecated and send a Sunset date

    The Sunset header (RFC 8594) gives the planned removal date machine-readably.

  45. 45. Which responses can HTTP caches store most safely?

    Correct answer: GET responses with explicit cache headers

    Personalized responses need Cache-Control: private or no-store so shared caches don't serve them to other users.

  46. 46. What is an ETag?

    Correct answer: An identifier of a specific resource version

    A client sends If-None-Match: <etag>; if nothing changed, the server replies 304 Not Modified without a body.

  47. 47. Why might an API compress responses?

    Correct answer: Gzip or Brotli shrink JSON and cut transfer time

    Clients send Accept-Encoding; servers answer with Content-Encoding. Compression costs CPU, so proxies or CDNs often do it.

  48. 48. What is GraphQL?

    Correct answer: A query language for APIs with a typed schema

    It reduces over- and under-fetching for complex UIs, but needs care with caching, query cost and N+1 problems on the server.

  49. 49. What is a webhook?

    Correct answer: An HTTP callback sent to your URL on an event

    Webhooks avoid constant polling. Receivers should verify signatures and handle duplicates.

  50. 50. What is gRPC typically used for?

    Correct answer: Fast, typed service-to-service calls

    It's popular inside microservice systems. Browsers need gRPC-Web or a proxy to use it.

  51. 51. What's the difference between REST and RPC style APIs?

    Correct answer: REST models resources; RPC exposes operations

    Both are valid. Many REST APIs include a few action endpoints (e.g. POST /orders/42:cancel in Google's style) for operations that don't map to CRUD.

  52. 52. When do Server-Sent Events fit better than polling?

    Correct answer: When the server should push updates as they happen

    SSE is one-way over HTTP; WebSockets are two-way. Polling is simplest but wastes requests and adds delay.

  53. 53. What does HEAD /files/report.pdf return?

    Correct answer: The same headers as GET, without the body

    Clients use it to check existence, size (Content-Length) or freshness without downloading the content.

  54. 54. Why are CORS preflight OPTIONS requests sent?

    Correct answer: The browser asks which methods and headers are allowed

    Servers can reduce preflights with Access-Control-Max-Age, which lets browsers cache the answer.

  55. 55. How should nested resources be used in URLs?

    Correct answer: One level deep, like /users/42/orders

    Deep nesting makes URLs long and forces clients to know the whole hierarchy. Items with their own IDs can also be accessed at the top level.

  56. 56. What's a sensible maximum for a list endpoint's limit parameter?

    Correct answer: A documented cap, like 100, with a smaller default

    Unbounded limits are a denial-of-service risk listed in the OWASP API Top 10 (unrestricted resource consumption).

  57. 57. Why might an API use a request ID header like X-Request-Id?

    Correct answer: To correlate logs and trace a failing request

    Return the ID in responses (especially errors) and pass it on to downstream calls.

  58. 58. Which tool is commonly used to try API requests manually?

    Correct answer: curl, Postman or Insomnia

    A browser address bar can only send GET requests without custom headers, which is rarely enough for API testing.

  59. 59. What does 'over-fetching' mean?

    Correct answer: The client receives more data than it needs

    REST APIs mitigate it with field selection (?fields=id,name) or tailored endpoints; GraphQL addresses it by design.

  60. 60. What does 'under-fetching' (or chatty API) mean?

    Correct answer: One screen needs many separate requests

    Options: embed or expand related resources (?include=author), add composite endpoints, a BFF, or GraphQL.

  61. 61. Should an API expose internal database IDs and table structure directly?

    Correct answer: No: design around the domain, not the database

    Mirroring the schema couples clients to internal details. Response models give you freedom to refactor.

  62. 62. How should boolean flags be named in API payloads?

    Correct answer: Positively, e.g. isActive or emailVerified

    Consider enums instead of booleans when more states may appear later (status: "active" | "suspended").

  63. 63. Why are enums in API responses tricky to extend?

    Correct answer: Clients may crash on values they don't know

    Adding an enum value can be a breaking change for strict clients. Some guidelines treat output enums as extensible by default.

  64. 64. What should a GET request never do?

    Correct answer: Change data on the server

    Crawlers, prefetching and caches may call GET URLs automatically. A 'delete' link as GET can wipe data unexpectedly.

  65. 65. What does Retry-After: 120 in a response mean?

    Correct answer: Wait 120 seconds before retrying

    It's used with 429 and 503. It can also be an HTTP date instead of seconds.

  66. 66. What is the Richardson Maturity Model?

    Correct answer: A scale of how RESTful an API is

    Most practical APIs sit at level 2: resources plus proper HTTP methods and status codes.

  67. 67. What is HATEOAS?

    Correct answer: Responses carry links to related actions

    It's part of Fielding's REST constraints. It's rarely used fully in practice, but pagination links are a common partial form.

  68. 68. A user double-clicks 'Pay', and the client sends POST /payments twice. What's the risk and a common fix?

    Correct answer: Two payments; send an Idempotency-Key header

    Stripe popularized idempotency keys. Disabling the button helps too, but retries after timeouts still need server-side protection.

  69. 69. What does 202 Accepted mean?

    Correct answer: Accepted for processing, but not finished yet

    It's typical for long-running jobs like reports or video processing.

  70. 70. How can a client follow a long-running operation started with 202 Accepted?

    Correct answer: It polls a status resource, or gets a webhook

    The status resource reports progress and, when finished, links to the result or describes the error.

  71. 71. When is it fine to create a resource with PUT?

    Correct answer: When the client chooses the resource's identifier

    Because PUT is idempotent, repeating it with the same body is safe: the resource ends up in the same state.

  72. 72. Why do many APIs return { "data": [...] } instead of a bare JSON array for lists?

    Correct answer: An object can later carry extra fields safely

    Top-level arrays can't be extended. An object wrapper keeps room for metadata.

  73. 73. What do headers like RateLimit-Remaining (or X-RateLimit-Remaining) give clients?

    Correct answer: How many requests are left in the current window

    Many APIs send limit, remaining and reset values. An IETF draft standardizes RateLimit header fields.

  74. 74. How can a client fetch several users by ID in one request in a REST API?

    Correct answer: With a collection filter like GET /users?ids=1,2,3

    Batch reads reduce round trips. Large ID lists may need POST /users:batchGet with a body because URLs have length limits.

  75. 75. What's a common query parameter name for free-text search in a collection?

    Correct answer: q, e.g. GET /products?q=laptop

    Whatever name you choose, use it consistently. Search often combines with filters and pagination.