REST API Interview Questions
An API that works on the happy path can still fail when a response is lost, two clients edit the same resource or a cache serves old data. Practice explaining how the HTTP contract handles those cases.
Try answering aloud before opening each explanation.
Try the REST API practice demoFoundations
How do a safe HTTP method and an idempotent method differ?
A safe method does not ask the server to change resource state; incidental logging is still allowed. An idempotent method has the same intended effect when the same request is repeated. DELETE is idempotent but not safe: repeating it can leave the resource absent even if the second response differs.
When would you use PUT rather than PATCH to update a resource?
Use PUT when the client supplies the desired replacement state for a known resource URI. Use PATCH when the body describes changes rather than the whole replacement. Whether a particular patch is idempotent depends on its operations and the API contract.
How do 201 Created and 202 Accepted differ for an export request?
Use 201 if the request has created the resource; give the client its URI when appropriate. Use 202 if processing was accepted but not completed. Returning a status URL gives the client a way to discover success or failure instead of treating acceptance as success.
When is 401 a better response than 403?
Use 401 when valid authentication credentials are missing or invalid; it carries an authentication challenge. Use 403 when the server understood the request but refuses it. An API may deliberately return 404 rather than disclose the existence of an inaccessible resource.
What belongs in a machine-readable validation error?
Include a stable problem type, an appropriate HTTP status, and actionable detail. Use a documented extension for field-level issues when needed. Clients should branch on the type or structured fields, not localized prose; do not emit stack traces or private submitted values.
Applied
How can clients retry a create request after the connection drops?
Use a client-provided idempotency key scoped to the caller and operation. Persist a record of the key and outcome atomically with the mutation, or implement an equivalent durable coordination mechanism. Reuse the stored outcome on replay, and reject the same key with a different request payload.
How can an API prevent two editors from silently overwriting one another?
Return a strong ETag with the representation. Require If-Match on writes and enforce the comparison atomically with the update. If the supplied validator no longer matches, respond with 412 so the caller can reload and reconcile rather than overwrite newer data.
What does a 304 response save, and when should a server send it?
It saves retransmitting a representation the client already has. A conditional GET carrying a matching validator can receive 304 without the response body. The client then reuses its cached representation and updates the relevant stored response metadata.
How do Cache-Control private and no-store differ?
Private disallows storage by a shared cache but can permit storage in the user's own cache. No-store directs caches not to store the response. Neither substitutes for authentication or for checking how application caches handle user-specific data.
Why include a tie-breaker in cursor pagination?
If rows share a timestamp, a cursor containing only that timestamp cannot distinguish their order. Sort by a stable pair such as timestamp and ID and encode both in the cursor. Document how updates or deletions affect the traversal; cursor pagination is not automatically a consistent snapshot.
Production scenarios
How should a client respond to a 429 rate-limit response?
Respect Retry-After when supplied. Otherwise use bounded backoff with jitter and cap attempts within an overall deadline. Retrying every rejected request immediately makes overload worse; confirm the operation is safe to repeat and avoid synchronized retry bursts.
What must an API verify before serving GET /projects/:id to a signed-in user?
Verify that the current user can access that particular project, not just that they have a valid session or a general role. Query through the membership or ownership scope and test that another user's project cannot be read. Apply the same rule to nested resources.
When can adding a response field still break old clients?
Clients may enforce an exact schema, generate brittle decoders or reinterpret a new enum value as an impossible case. Document extension rules, use tolerant readers where possible and test representative old clients before relying on additive compatibility.
How do you model a slow export without keeping an HTTP request open?
Accept the submission and expose a job resource with pending, complete and failed states. Return a status link the authorized caller can poll with backoff. Separate job status from the lifetime of the resulting download and define replay and expiration behavior.
What should you measure when a list endpoint grows slow for larger tenants?
Break latency into authorization, database work, serialization and response size. Compare query plans and row counts across tenant sizes, enforce bounded page sizes and check indexes against the actual filtering and ordering. An average across tenants can hide the slow path.
Further reading
Official documentation
Related question sets
- Node.js interview questions
- TypeScript interview questions
- Microservices interview questions
- SQL interview questions
- Python interview questions
- JavaScript interview questions
- React interview questions
- Kubernetes interview questions
- System Design interview questions
- Java interview questions
- Docker interview questions
- MongoDB interview questions
- PostgreSQL interview questions
- Redis interview questions
- NestJS interview questions
- RabbitMQ interview questions