RESTful API Design Questions
Designing resource-oriented HTTP APIs following REST constraints: resource modeling, URI structure, correct use of HTTP methods, statelessness, and HATEOAS trade-offs. Covers naming conventions, collection vs. singleton resources, filtering/sorting/pagination, and choosing appropriate status codes. The default paradigm most interview questions in this category probe.
Explain what idempotency means for an HTTP operation, and give one read-only and one state-changing example where it matters. A client can retry a POST that creates a resource because the response was lost on the network, even though the resource was actually created. Describe a design using a client-supplied idempotency key that prevents that retry from creating a duplicate, including what you store, for how long, and what you return to a client that reuses a key.
Write the SQL for keyset pagination against a table posts(id BIGINT PRIMARY KEY, created_at TIMESTAMP, title TEXT), returning the next 50 posts after a given cursor of (last_created_at, last_id). Say which index supports this query efficiently, and how you break ties when created_at is not unique across rows.
Show what a JSON response for an order resource would look like if it included hypermedia links for the actions currently available on it (for example pay, cancel, and view items). Explain what HATEOAS is supposed to buy a client that the links alone would not otherwise know, and give the concrete reason most public REST APIs today skip full hypermedia even though the specification recommends it.
You are designing the error handling for an API. Pick the single most appropriate HTTP status code, and briefly justify it, for each of: malformed JSON in the request body, a validation error on a business rule, an authentication failure, an authorization failure, a request for a resource that does not exist, a request accepted for asynchronous processing, and a successful resource creation versus a successful update with no content to return. Name one common mistake engineers make on at least two of these.
Design the query-parameter contract for a GET /products list endpoint that needs to support multi-field sorting, range filters (for example a price range), boolean and enum flags, and a full-text match on a description field, while staying discoverable and unambiguous to a client reading the URL. What safeguards do you put in place so a client-constructed filter cannot trigger an expensive ad-hoc query that degrades the service for everyone else?
Unlock Full Question Bank
Get access to all 39 RESTful API Design interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.