REST API and API design interview questions and answers
REST API interview questions test whether you know HTTP well enough to design an interface other teams can rely on: the right method, status code and URL for each operation, safe retries, pagination, versioning, errors and security. API design interview questions take the same knowledge into an open exercise where you sketch the endpoints for a product and defend each choice. Candidates who explain idempotency, caching and backward compatibility, not only CRUD routes, stand out.
By Evin JohnPublished 8 min read
Where REST and API design questions are asked
Backend, full-stack and platform interviews almost always include API questions. They show up three ways: quick knowledge checks on HTTP in a phone screen, a review of an existing endpoint ("what is wrong with POST /getUserOrders?"), and an API design round where you design the interface for something like a booking or payments product. The design round is close to a system design interview but stops at the contract: resources, operations, payloads, errors and how the API changes over time. Senior candidates are also asked when REST is the wrong choice.
HTTP and REST fundamentals
| Question | What it tests | What a strong answer shows |
|---|---|---|
| What makes an API RESTful? | Principles | Resources identified by URLs, a uniform interface built on standard HTTP methods, stateless requests that carry everything needed, cacheable responses, and a layered system. Most real APIs are "REST-like" and that is fine if they are consistent. |
| Which HTTP methods are safe, and which are idempotent? | Semantics | GET, HEAD and OPTIONS are safe (no intended side effects). PUT and DELETE are idempotent but not safe. POST is neither, and PATCH is not guaranteed to be idempotent. |
| PUT versus PATCH? | Updates | PUT replaces the resource with the representation sent, so repeating it gives the same state. PATCH applies a partial change; JSON Merge Patch and JSON Patch are common formats. |
| What does stateless mean here? | Scaling | The server keeps no session between requests; each request carries its credentials and context. Any instance can serve any request, which makes horizontal scaling simple. |
| What status code should creating a resource return? | Status codes | 201 Created with a Location header pointing at the new resource, and usually the resource in the body. |
| When do you return 204? | Status codes | When the request succeeded and there is no body to send, such as a DELETE or a PUT whose result the client already has. |
| 401 versus 403? | Auth semantics | 401 means the request is not authenticated (missing or invalid credentials). 403 means the caller is known but not allowed. Some APIs return 404 instead of 403 to avoid revealing that a resource exists. |
| 400 versus 422? | Validation | 400 for a request the server cannot parse or that is malformed. 422 for well-formed JSON that fails business validation, such as an end date before the start date. Pick one convention and document it. |
| What is 409 Conflict for? | State | The request clashes with the current state: a duplicate unique name, or an order that cannot be canceled because it already shipped. |
| 302 versus 307 and 301 versus 308? | Redirects | 307 and 308 require the client to repeat the same method and body. 301 and 302 historically let clients switch a POST to a GET, which is why APIs prefer the newer codes. |
Resource and URL design questions
- What is wrong with `POST /getUserOrders`? The verb is in the URL and the method does not match a read. Model the resource:
GET /users/{id}/orders, orGET /orders?userId={id}if orders are queried in many ways. - Plural or singular collection names? Plural nouns (
/orders,/orders/{id}) are the common convention. Consistency across the whole API matters more than the choice. - How deep should nesting go? One level of ownership (
/projects/{id}/tasks) reads well. Beyond that, give the child its own top-level route (/tasks/{id}) so clients do not need every parent ID. - How do you model an action that is not CRUD, like "cancel order"? Either a state change (
PATCH /orders/{id}withstatus: canceled) or a sub-resource for the action (POST /orders/{id}/cancellation). Explain how each handles validation and audit history. - How do you design filtering and sorting? Query parameters with clear names (
?status=open&sort=-createdAt), an allow-list of sortable fields backed by indexes, and documented defaults. - Offset or cursor pagination? Offset (
?page=5) is simple but slow on large tables and skips or repeats items when rows are inserted. A cursor encodes the position after the last item seen, stays fast with an index, and is stable while data changes. Return the next cursor in the response. - How do you return a large export or a slow job? Accept with 202, return a job resource (
/exports/{id}) the client can poll or be notified about by webhook, and give a download link when it finishes. - Should IDs be sequential integers? They leak volume and invite enumeration. Random or time-ordered IDs (such as UUIDv7 or ULID) avoid that while keeping index locality.
GET /v1/orders?status=open&limit=2 HTTP/1.1
Host: api.example.com
Authorization: Bearer <token>
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: private, max-age=0
{
"data": [
{ "id": "ord_9f2", "status": "open", "createdAt": "2026-11-30T10:04:00Z" },
{ "id": "ord_9e7", "status": "open", "createdAt": "2026-11-30T09:51:00Z" }
],
"nextCursor": "eyJjIjoiMjAyNi0xMS0zMFQwOTo1MTowMFoiLCJpZCI6Im9yZF85ZTcifQ"
}Errors, versioning and compatibility
| Question | What it tests | What a strong answer shows |
|---|---|---|
| What should an error response contain? | Error design | A stable machine-readable code, a human message, the field at fault for validation errors, and a request or trace ID. RFC 9457 "problem details" is a standard shape many teams adopt. |
| URL versioning or header versioning? | Versioning | /v1/... is visible, cache-friendly and easy to route. Header or media-type versioning keeps URLs clean but is harder to test by hand. Either works if breaking changes are rare. |
| What counts as a breaking change? | Compatibility | Removing or renaming a field, changing a type or meaning, adding a required input, tightening validation, or changing an error code clients branch on. Adding an optional field or a new endpoint usually is not. |
| How do you retire an old endpoint? | Lifecycle | Announce it, mark it deprecated in the docs and with a response header, measure who still calls it, contact those clients, and only then remove it. |
| How do clients stay safe when you add enum values? | Robustness | Document that new values can appear and ask clients to handle unknown ones. Otherwise a new status breaks a strict switch statement on the client. |
| How do you document an API? | Contracts | An OpenAPI description kept next to the code and checked in CI, with examples for each error. Generated clients and contract tests then catch drift. |
Security, caching and reliability questions
- API key, OAuth 2.0 or session cookie? API keys identify a calling system and suit server-to-server use. OAuth 2.0 lets a user grant an app limited access without sharing a password, with scopes and expiring tokens. Cookies suit a browser talking to its own backend.
- What are the risks of JWT access tokens? They are hard to revoke before expiry, can grow large, and are dangerous if the signature algorithm is not pinned. Keep them short-lived, validate issuer, audience and expiry, and never put secrets in the payload, which is only encoded.
- What is object-level authorization and why does it fail so often? Checking that this caller may access this particular record, not just this endpoint. Skipping it lets a user change an ID in the URL and read someone else's data.
- How do ETags help? A client sends
If-None-Matchwith the ETag it has; if nothing changed the server answers 304 with no body. WithIf-Matchon an update, the server returns 412 if someone else changed the resource first, which prevents lost updates. - How do you make POST safe to retry? Accept an
Idempotency-Keyheader, store the key with the first result, and return the stored result for any repeat with the same key and body. Payments APIs depend on this. - How do you rate limit an API and tell clients about it? Count requests per key or user with a token bucket or sliding window, return 429 when the limit is hit, and include
Retry-After. The design behind it is in designing a rate limiter. - What is CORS and when does a preflight happen? Browsers block cross-origin reads unless the server allows the origin. Requests with non-simple methods or headers (such as
Authorizationor JSON content type) trigger an OPTIONS preflight first. - How do you make webhooks reliable? Sign each payload so receivers can verify it, retry with backoff on failure, include an event ID so receivers can ignore duplicates, and let them fetch the current state rather than trusting event order.
const http = require("node:http");
const crypto = require("node:crypto");
const seen = new Map(); // idempotency key -> { hash, status, body }
function send(res, status, body) {
res.writeHead(status, { "Content-Type": "application/json" });
res.end(JSON.stringify(body));
}
http.createServer((req, res) => {
if (req.method !== "POST" || req.url !== "/v1/payments") return send(res, 404, { code: "not_found" });
const key = req.headers["idempotency-key"];
if (!key) return send(res, 400, { code: "idempotency_key_required" });
let raw = "";
req.on("data", (chunk) => (raw += chunk));
req.on("end", () => {
const hash = crypto.createHash("sha256").update(raw).digest("hex");
const prior = seen.get(key);
if (prior && prior.hash !== hash) return send(res, 422, { code: "key_reused_with_different_body" });
if (prior) return send(res, prior.status, prior.body); // replay, no second charge
const payment = { id: "pay_" + crypto.randomUUID(), ...JSON.parse(raw || "{}"), status: "succeeded" };
seen.set(key, { hash, status: 201, body: payment });
send(res, 201, payment);
});
}).listen(3000);API design round and senior questions
| Question | What it tests | What a strong answer shows |
|---|---|---|
| Design the API for a ticket booking product. | End-to-end design | Resources (events, seats, holds, bookings), a hold with an expiry before payment, idempotent booking creation, 409 when a seat is taken, and how the client learns a hold expired. See the ticket booking design. |
| REST, GraphQL or gRPC? | Trade-offs | REST for public, cacheable resource APIs; GraphQL when many clients need different shapes of linked data; gRPC for typed, high-throughput service-to-service calls. Teams often use more than one. |
| How would you design a public API that partners pay for? | Product thinking | Keys per partner, scopes, quotas and usage reporting, a sandbox, strong versioning promises, status page and changelog. |
| How do you handle a field that is expensive to compute? | Performance | Make it opt-in with an expand or fields parameter, cache it, or move it to its own sub-resource. |
| How do you keep a list endpoint fast as data grows? | Scale | Cursor pagination on an indexed sort key, a maximum page size, filters backed by indexes, and no total count unless it is cheap or approximated. |
| A client calls your API 50 times to render one screen. What do you do? | Chattiness | Look at whether a composite endpoint, embedding related resources, a batch endpoint or a backend-for-frontend layer fits better than many small calls. |
Fictional example
- Interviewer
- Users have lists, lists have items, and a list can be shared with other users. Sketch the API.
- Candidate
- I would start with three resources: lists, items and memberships.
GET /listsreturns lists the caller can see, with cursor pagination.POST /listsreturns 201 and a Location header. Items live under their list for creation and listing,POST /lists/{listId}/itemsandGET /lists/{listId}/items, but each item also has/items/{id}so clients can update it without knowing the list. Sharing isPOST /lists/{listId}/memberswith a user and a role, and 409 if they are already a member. Every route checks that the caller is a member of that specific list, and a non-member gets 404 so list IDs do not leak. For two people editing the same item I would return an ETag and requireIf-Matchon PATCH, answering 412 on a conflict so the client can refresh. Errors follow one shape with a code and the field at fault. If the mobile app needs offline sync later, I would add a changes feed with a cursor instead of making clients reload every list.
How to practice API design
- Learn the codes you will be asked aboutWrite one line each for 200, 201, 202, 204, 301, 304, 307, 400, 401, 403, 404, 409, 412, 422, 429, 500, 502, 503 and 504, with a real example.
- Critique a real APIRead the reference of a well-known public API and list what it does for pagination, errors, versioning and idempotency. Note where it breaks its own rules.
- Design three APIs on paperA shared to-do list, a payments flow and a file upload service. For each, write resources, methods, status codes and two error cases.
- Build one endpoint for realRun the idempotency example above, send the same request twice with curl, then send a different body with the same key and check you get 422.
- Defend choices aloudPractice saying why for each decision: why a cursor, why 404 instead of 403, why a header for versioning or not.
API design connects to the rest of backend preparation: microservices interview questions covers how services call each other, backend developer interview questions covers the wider role, and the payment system design shows idempotency at scale.
Design rounds reward talking through trade-offs in order, and you only notice gaps when you read them back. Natively, an AI interview assistant on Mac and Windows, transcribes a practice design session so you can check whether you covered errors, auth and versioning or ran out of time on routes. In practice it can read a screenshot of an endpoint spec or a failing response and suggest what to question, and with Pro or the free trial it can draw on the résumé and job description you add. Each session's transcript and notes are kept on your computer.
Questions people ask
What REST API questions are asked in interviews?
Safe and idempotent methods, PUT versus PATCH, status codes such as 401 versus 403, resource naming, pagination, versioning, error formats, authentication, caching with ETags and rate limiting.
What is asked in an API design interview?
You design the endpoints for a product such as a booking or payments service: resources, methods, payloads, status codes, errors, pagination, auth and how the API can change without breaking clients.
What is the difference between PUT and PATCH?
PUT replaces the whole resource with what you send and is idempotent. PATCH sends a partial change, and repeating it is not guaranteed to give the same result.
How do you make a POST request safe to retry?
Have clients send an idempotency key. The server stores the key with the first result and returns that same result for any repeat, so a retry after a timeout does not create a duplicate.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
