RMRM Full Stack & AI Engineer · All questions · Roadmaps
Backend · interview questions

REST API Interview Questions

REST API interview questions covering HTTP fundamentals, design principles, authentication, versioning, error handling, and advanced patterns. Spans beginner to advanced difficulty.

1. What does REST stand for and what are its core principles?

beginner

REST stands for Representational State Transfer. Its core principles are: statelessness, client-server architecture, cacheability, uniform interface, layered system, and optional code-on-demand.

2. What is the difference between PUT and PATCH?

beginner

PUT replaces the entire resource with the provided data, requiring the full representation in the request body. PATCH applies a partial update, sending only the fields that need to change.

3. What are the standard HTTP status code categories and give one example each?

beginner

1xx Informational (100 Continue), 2xx Success (200 OK), 3xx Redirection (301 Moved Permanently), 4xx Client Error (404 Not Found), 5xx Server Error (500 Internal Server Error).

4. What is the difference between 401 Unauthorized and 403 Forbidden?

beginner

401 means the client is not authenticated — credentials are missing or invalid. 403 means the client is authenticated but does not have permission to access the resource.

5. What makes an API truly RESTful vs just HTTP-based?

intermediate

A truly RESTful API must follow all REST constraints: stateless communication, uniform interface (resource-based URIs, standard HTTP methods, HATEOAS), and proper use of HTTP semantics like caching headers and status codes. Many APIs use HTTP but skip constraints like HATEOAS, making them REST-like but not fully RESTful.

6. What is HATEOAS and why is it important?

intermediate

HATEOAS (Hypermedia As The Engine Of Application State) means the API response includes links to related actions and resources, letting clients navigate the API dynamically without hardcoded URLs. It improves discoverability and decouples the client from the server's URL structure.

7. How do you version a REST API and what are the trade-offs of each approach?

intermediate

Common strategies are URI versioning (/v1/users), query parameter (?version=1), and Accept header versioning (Accept: application/vnd.api.v1+json). URI versioning is most visible and easy to test but pollutes the URL; header versioning is cleaner but harder to test in a browser; query params are simple but can conflict with caching.

8. What is idempotency and which HTTP methods are idempotent?

intermediate

An operation is idempotent if making the same request multiple times produces the same server state as making it once. GET, PUT, DELETE, HEAD, and OPTIONS are idempotent; POST and PATCH are generally not.

9. How would you handle authentication and authorization in a REST API?

intermediate

Common approaches are API Keys (simple but limited), OAuth 2.0 with Bearer tokens for delegated authorization, and JWT for stateless token-based auth. Tokens are sent in the Authorization header (Bearer scheme) and validated on each request since REST is stateless.

10. What is the difference between REST and GraphQL, and when would you choose one over the other?

intermediate

REST exposes multiple fixed endpoints per resource; GraphQL exposes a single endpoint where clients query exactly the data they need. Choose REST for simple, cacheable, resource-oriented APIs; choose GraphQL when clients have highly varied data needs or you want to avoid over- and under-fetching.

11. How do you design pagination for a REST API?

intermediate

Common strategies are offset/limit (?offset=20&limit=10), page-based (?page=3&per_page=10), and cursor-based pagination using an opaque cursor token. Cursor-based is preferred for large or real-time datasets because it is stable under insertions/deletions, while offset pagination is simpler but can return duplicates or skip records on concurrent writes.

12. How would you implement rate limiting in a REST API?

intermediate

Rate limiting is typically enforced at the API gateway or middleware level using algorithms like token bucket or sliding window counter. The server returns 429 Too Many Requests with Retry-After or X-RateLimit-* headers so clients know when they can retry.

13. What are the best practices for REST API error responses?

intermediate

Error responses should use the appropriate HTTP status code, return a consistent JSON body with fields like error code, human-readable message, and optionally a details array or a link to documentation. Avoid exposing internal stack traces or sensitive system information in production error payloads.

14. Explain the N+1 problem in REST APIs and how to solve it.

advanced

The N+1 problem occurs when fetching a list of N resources then making one additional request per item to fetch related data, resulting in N+1 total requests. Solutions include eager loading/embedding related data in the response, implementing compound documents, using sparse fieldsets, or switching to GraphQL which resolves all fields in one query.

15. How would you design a REST API for a resource that has long-running operations?

advanced

Use the async request-reply pattern: the POST immediately returns 202 Accepted with a Location header pointing to a status resource (e.g., /jobs/123). The client polls that endpoint until it returns 200 with the result or 303 See Other redirecting to the completed resource. Alternatively, use webhooks to push the result when ready.

16. What is content negotiation in REST APIs and how does it work?

advanced

Content negotiation allows clients and servers to agree on the format of the response. The client sends an Accept header (e.g., Accept: application/json) and the server responds with that format and a Content-Type header confirming it, or returns 406 Not Acceptable if the format is unsupported.

17. How do you handle API backward compatibility when making breaking changes?

advanced

Strategies include: maintaining multiple versions simultaneously, using API sunset headers to deprecate old versions with a migration timeline, feature flags to toggle new behavior, and designing additive changes (new optional fields) whenever possible. Breaking changes should always increment the major API version.

18. What is the role of ETags and conditional requests in REST APIs?

advanced

An ETag is a hash or version identifier returned in the response header representing the current state of a resource. Clients can send it back in If-None-Match (for GETs) to receive 304 Not Modified if unchanged, reducing bandwidth, or in If-Match (for PUT/DELETE) to implement optimistic concurrency control and prevent lost updates.

Practice these out loud with an AI interviewer that grills you and grades your answers.
Open the app — free to start

© RM Full Stack & AI Engineer · All interview questions · Roadmaps · Open the app