Software Engineer | 46 questions | 2026
REST API Interview Questions and Answers
REST API interview questions for freshers 20
Q1FresherMost askedAnswerHideWhat is a REST API and what are the REST principles?
REST (Representational State Transfer) is a style for building APIs. Each resource has a URL, and you use standard HTTP methods to work with it.
Core constraints:
- Client-server: UI and data storage are separated.
- Stateless: each request carries everything needed. The server keeps no session between calls.
- Cacheable: responses declare whether they can be cached.
- Uniform interface: resource URIs, standard methods, representations such as JSON, and (ideally) hypermedia links.
- Layered system: proxies, gateways and load balancers can sit between the client and the server.
- Code on demand (optional): the server can send code to run on the client.
Example: GET /users/42 returns user 42, DELETE /users/42 removes it. Use nouns in URLs and let the HTTP method express the action.
What they are checking: Whether you know the constraints, not only 'it uses JSON over HTTP'
Q2FresherMost askedAnswerHideWhat are the main HTTP methods and what is each used for?
| Method | Purpose | Safe | Idempotent |
|---|---|---|---|
| GET | Read a resource | Yes | Yes |
| POST | Create a resource or trigger an action | No | No |
| PUT | Replace a resource entirely | No | Yes |
| PATCH | Partially update a resource | No | Not guaranteed |
| DELETE | Remove a resource | No | Yes |
| HEAD | Like GET but headers only | Yes | Yes |
| OPTIONS | Describe allowed methods (used by CORS preflight) | Yes | Yes |
Example mapping for a books collection:
GET /bookslist,POST /bookscreateGET /books/7read,PUT /books/7replace,PATCH /books/7update fields,DELETE /books/7remove
Safe means it does not change server state. Idempotent means repeating the call has the same effect as calling it once.
What they are checking: What each method means, including safe and idempotent
Q3FresherMost askedAnswerHideWhat is the difference between PUT and PATCH?
PUT replaces the whole resource with the body you send. PATCH applies a partial change to only the fields you send.
Existing user: {"name": "Asha", "email": "[email protected]", "city": "Pune"}
PUT /users/1
{"name": "Asha K", "email": "[email protected]"}
Result: city is gone (the resource is now exactly what was sent), so clients must send the full representation.
PATCH /users/1
{"name": "Asha K"}
Result: only name changes, email and city stay.
- PUT is idempotent by definition.
- PATCH can be idempotent (for example, set a field to a value). But it is not guaranteed (for example, an "increment by 1" operation).
- Prefer PATCH for small edits to large objects. It saves bandwidth and avoids overwriting other people's changes.
What they are checking: Replace vs partial update with an example
Q4FresherMost askedAnswerHideWhat is the difference between PUT and POST?
POST creates a subordinate resource and the server usually chooses the id. PUT creates or replaces a resource at a URL the client specifies.
| POST | PUT | |
|---|---|---|
| Target URL | Collection (/orders) | Specific resource (/orders/15) |
| Idempotent | No: two calls create two orders | Yes: two calls leave one result |
| Typical response | 201 Created with Location header | 200 OK or 204, or 201 if created |
| Use for | Create, actions, non-CRUD operations | Full replace, upsert with a client-known id |
Because POST is not idempotent, a client retry after a timeout can create duplicates. That is why payment APIs accept an idempotency key with POST.
What they are checking: Idempotency and who chooses the id
Q5FresherMost askedAnswerHideWhat does idempotent mean in REST and which methods are idempotent?
An operation is idempotent if performing it once or many times leaves the server in the same state. The response may be different, but the effect must be the same.
- Idempotent: GET, HEAD, OPTIONS, PUT, DELETE.
- Not idempotent: POST, and PATCH in general.
Example: DELETE /users/5 the first time returns 204 and removes the user. The second time returns 404. But the end state is the same: user 5 does not exist. POST /orders twice creates two orders.
Why it matters: networks fail, so clients and gateways retry. Idempotent calls are safe to retry. For POST, make retries safe with an Idempotency-Key header: the server saves the key with the result. If the same key comes again, it returns the saved result.
What they are checking: Retry-safety reasoning
Q6FresherMost askedAnswerHideWhat are the common HTTP status codes and what do they mean?
Grouped by class:
- 1xx informational:
101 Switching Protocols(WebSocket upgrade). - 2xx success:
200 OK,201 Created,202 Accepted(queued for async work),204 No Content. - 3xx redirection:
301 Moved Permanently,302 Found,304 Not Modified(cached copy valid). - 4xx client error:
400 Bad Request,401 Unauthorized(not authenticated),403 Forbidden(authenticated but not allowed),404 Not Found. Also405 Method Not Allowed,409 Conflict,422 Unprocessable Content(valid syntax, failed validation),429 Too Many Requests. - 5xx server error:
500 Internal Server Error,502 Bad Gateway,503 Service Unavailable,504 Gateway Timeout.
Return the most specific code. Never return 200 with an error in the body, because clients and monitoring tools rely on the status.
What they are checking: Precise use of codes
Q7FresherMost askedAnswerHideWhat is the difference between 401 and 403?
401 Unauthorized means the request lacks valid authentication: no token, an expired token, or wrong credentials. The client should authenticate and retry. Include a WWW-Authenticate header.
403 Forbidden means the server knows who you are but you are not allowed to do this. Logging in again will not help.
Examples:
- Calling
/orderswith noAuthorizationheader: 401. - A normal user calling
DELETE /users/9: 403. - Some APIs return 404 instead of 403 when a user should not even know the resource exists. This hides that it exists.
What they are checking: Authn vs authz mapped to codes
Q8FresherMost askedAnswerHideWhat is the difference between authentication and authorization?
Authentication proves who you are. Authorization decides what you are allowed to do.
| Authentication | Authorization | |
|---|---|---|
| Question | Who are you? | What can you access? |
| Happens | First | After authentication |
| Mechanisms | Passwords, MFA, tokens, certificates | Roles, permissions, scopes, ACLs, policies |
| Failure code | 401 | 403 |
Analogy: showing your ID at the building entrance is authentication; the badge that opens only certain floors is authorization.
In an API, the token proves identity (authentication). Then the code checks that the user's role or scope allows DELETE /projects/3 and that they own that project (authorization).
What they are checking: Core security distinction
Q9FresherMost askedAnswerHideWhat is a JWT and how does it work?
A JSON Web Token (JWT) is a small, signed token that carries information (claims) between two parties. It has three Base64URL parts separated by dots: header.payload.signature.
- Header: algorithm and type, for example
{"alg": "RS256", "typ": "JWT"}. - Payload: claims such as
sub(user id),exp(expiry),iss,aud, roles. - Signature: made from the header and payload with a secret (HMAC) or a private key (RSA/ECDSA).
Flow: the user logs in and the server gives back a JWT. The client sends Authorization: Bearer <token> on later calls. The server checks the signature and expiry, with no session lookup.
Important points:
- The payload is encoded, not encrypted: never put secrets in it.
- Always check the signature,
exp,issandaud. Allow only the algorithm you expect. - Tokens are hard to cancel before they expire. So keep access tokens short-lived (5 to 15 minutes) and use refresh tokens.
What they are checking: Understanding structure and pitfalls
Q10FresherMost askedFree with sign-inAnswerHideHow do you implement pagination in a REST API?
Never return an unbounded list. Common styles:
Q11FresherMost askedFree with sign-inAnswerHideWhat is CORS and why does it exist?
Cross-Origin Resource Sharing (CORS) is a browser rule. It controls which other origins can call your API from JavaScript. An origin is scheme plus host plus port. By default, the same-origin policy stops a page on https://app.com from reading responses from https://api.com.
Q12FresherMost askedFree with sign-inAnswerHideWhat is the difference between hashing, encryption and encoding? Which one do you use for passwords?
They solve different problems:
Q13FresherMost askedFree with sign-inAnswerHideWhat makes a good REST URL design? Give naming conventions.
Use nouns for resources, plural collections, and let the HTTP method be the verb.
Good:
GET /usersandGET /users/42GET /users/42/orders(nested only one or two levels deep)POST /users,DELETE /users/42
Q14FresherMost askedFree with sign-inAnswerHideWhat is the difference between stateless and stateful, and why is REST stateless?
In a stateful service, the server remembers the client between requests (a server-side session). In a stateless service, every request has all the information needed, such as an auth token and parameters. The server stores nothing about the previous call.
Q15FresherMost askedFree with sign-inAnswerHideWhat is the difference between SOAP and REST?
| SOAP | REST | |
|---|---|---|
| Type | Protocol with strict rules | Architectural style |
| Format | XML only | JSON, XML, others (JSON typical) |
| Contract | WSDL | OpenAPI (optional) |
| Transport | HTTP, SMTP, others | HTTP |
| Weight | Heavier, long XML envelope | Lightweight |
| Security | WS-Security built in... |
Q16FresherMost askedFree with sign-inAnswerHideWhat are webhooks and how are they different from polling?
A webhook is an HTTP callback. When an event happens, the provider sends a POST to a URL you registered. Polling means your client keeps asking "anything new?".
Q17FresherMost askedFree with sign-inAnswerHideHow do you document and test a REST API?
Documentation: describe the API with an OpenAPI (Swagger) spec. It lists endpoints, parameters, schemas, auth and error responses. Make interactive docs (Swagger UI, Redoc) and client SDKs from it. Keep the spec in version control. Ideally, create or check it from the code so it stays correct.
Q18FresherMost askedFree with sign-inAnswerHideWhat is the difference between an API key, a bearer token and basic authentication?
- Basic auth: the client sends
Authorization: Basic base64(user:password)on every request. It is only Base64 encoded, so you must use HTTPS. The password is sent on every call. It is fine for simple internal tools. - API key: a long random string that identifies the calling application. It is sent in a header...
Q19FresherMost askedFree with sign-inAnswerHideWhat are the differences between query parameters, path parameters and request body? When should each be used?
- A path parameter identifies one resource:
GET /users/42. It is required. - A query parameter filters, sorts or pages a list:
GET /users?role=admin&sort=name&limit=20. Usually optional. - The request body carries the data to create or update:
POST /userswith JSON. It is used with POST, PUT and PATCH. - Headers carry extra information such as auth, content type, idempotency key and version.
Q20FresherMost askedFree with sign-inAnswerHideWhat is the difference between synchronous and asynchronous APIs?
A synchronous API holds the connection until the work is done and returns the final result. The client waits.
An asynchronous API accepts the request and replies at once (usually 202 Accepted). The result comes later through polling, a webhook, or a stream.
REST API interview questions for experienced 17
Q21ExperiencedMost askedAnswerHideWhat is OAuth 2.0 and which grant types exist?
OAuth 2.0 is an authorization framework. It lets an app use a user's data on another service without getting the user's password. It gives the app an access token with limited permissions (scopes).
Roles: resource owner (user), client (app), authorization server, resource server (API).
Main flows:
- Authorization Code with PKCE: for web, mobile and SPA apps. The user logs in at the provider, and the app trades a code for tokens. This is the recommended default.
- Client Credentials: service-to-service, no user involved.
- Refresh Token: gets new access tokens without a new login.
- Device Code: for TVs and CLIs without a browser.
- Implicit and Resource Owner Password flows are old and should be avoided.
OAuth 2.0 handles authorization. OpenID Connect adds an ID token on top, for login ("Sign in with Google").
What they are checking: Flow choice and the OAuth versus OIDC distinction
Q22ExperiencedMost askedFree with sign-inAnswerHideHow do you version a REST API?
Versioning lets you change the API without breaking existing clients. Common strategies:
Q23ExperiencedMost askedFree with sign-inAnswerHideWhat is rate limiting and how would you implement it in an API?
Rate limiting limits how many requests a client can make in a time window. It protects the service from abuse and overload.
Q24ExperiencedMost askedFree with sign-inAnswerHideWhat is the difference between REST, GraphQL and gRPC? When would you choose each?
| REST | GraphQL | gRPC | |
|---|---|---|---|
| Style | Resources over HTTP | Single endpoint, client-defined queries | Remote calls with Protocol Buffers |
| Transport | HTTP/1.1 or 2, JSON | HTTP, JSON | HTTP/2, binary |
| Over/under-fetching | Common | Solved, client picks fields | Fixed messages |
| Caching | Easy... |
Q25ExperiencedMost askedFree with sign-inAnswerHideHow do you handle errors in a REST API? What should an error response look like?
Use the correct status code and a consistent body that programs can read. The standard format is Problem Details (RFC 9457, previously 7807):
Q26ExperiencedMost askedFree with sign-inAnswerHideWhat is the difference between OAuth 2.0 and OpenID Connect?
OAuth 2.0 answers "what may this app access?" and produces an access token for APIs. OpenID Connect (OIDC) is a small identity layer on top of OAuth 2.0. It answers "who is the user?". It gives an ID token (a JWT) with details about the user.
Q27ExperiencedMost askedFree with sign-inAnswerHideWhere should a client store a JWT or token in a web app?
There is no perfect place; choose by threat model.
Q28ExperiencedMost askedFree with sign-inAnswerHideWhat is a CORS preflight request?
A preflight is an automatic OPTIONS request. The browser sends it before the real request when the call is not simple. For example, when it uses PUT/DELETE, a JSON Content-Type, or an Authorization header.
Q29ExperiencedMost askedFree with sign-inAnswerHideHow does HTTP caching work for APIs? Explain Cache-Control.
Caching reuses saved responses to cut delay and load. The server controls it with headers.
Q30ExperiencedMost askedFree with sign-inAnswerHideWhat is an API gateway and what does it do?
An API gateway is one entry point in front of the backend services. It handles shared jobs, so each service does not have to.
Q31ExperiencedMost askedFree with sign-inAnswerHideWhat are the advantages and disadvantages of GraphQL?
Advantages:
- Clients ask for exactly the fields they need. This removes extra data and extra round trips.
- One endpoint and a typed schema, with good tools.
- You can change it without versions by marking old fields as deprecated.
Q32ExperiencedMost askedFree with sign-inAnswerHideWhat is HATEOAS?
HATEOAS stands for Hypermedia As The Engine Of Application State. Responses include links that tell the client what it can do next. The client follows the links instead of fixing the URLs in its code.
Q33ExperiencedMost askedFree with sign-inAnswerHideWhat is an ETag and how is it used for caching and concurrency control?
An ETag is an identifier for one version of a resource (often a hash or a version number). It is returned in the ETag header.
Caching with conditional GET:
GET /products/5
-> 200, ETag: "v7"
GET /products/5
If-None-Match: "v7"
-> 304 Not Modified (no body, saves bandwidth)
Q34ExperiencedMost askedFree with sign-inAnswerHideWhat is idempotency key best practice for retrying failed requests on the client side?
Retry only when it is safe, and spread the retries out.
Q35ExperiencedMost askedFree with sign-inAnswerHideHow would you design an API that is easy for other developers to use?
Treat the API like a product.
Q36ExperiencedMost askedFree with sign-inAnswerHideWhat is PKCE in OAuth 2.0, and why do single-page and mobile apps need it?
PKCE (Proof Key for Code Exchange, said "pixie") protects the authorization code flow. It is for apps that cannot keep a secret, such as browser and mobile apps. It stops an attacker who steals the authorization code from trading it for tokens.
Q37ExperiencedFree with sign-inAnswerHideHow do caching and federation work in an Apollo GraphQL setup, and what problems do they solve?
Caching happens at several levels:
- Client: Apollo Client keeps one cache entry per object, found by its type and id. When an object changes, every query that shows it updates. Fetch policies such as
cache-firstandnetwork-onlydecide when it asks the server. - Server: cache hints per field and...
Scenario based REST API interview questions 9
Q38ExperiencedMost askedScenarioFree with sign-inAnswerHideDesign a REST API for a simple blog with posts and comments.
Resources: posts and comments (comments belong to a post).
Q39ExperiencedMost askedScenarioFree with sign-inAnswerHideDesign the API for an order and payment flow so a network retry never charges a customer twice.
Use idempotency keys on the non-idempotent POST calls.
Q40ExperiencedMost askedScenarioFree with sign-inAnswerHideHow would you secure a REST API?
Use many layers of defence:
Q41ExperiencedMost askedScenarioFree with sign-inAnswerHideAn endpoint that lists orders is slow under load. How do you improve its performance?
First find the slow part with tracing, logs and database EXPLAIN. Then use the cheapest fix that works.
Q42ExperiencedMost askedScenarioFree with sign-inAnswerHideA frontend developer says the API works in Postman but fails in the browser with a CORS error. How do you debug it?
Postman does not enforce CORS. The browser does. So the problem is in the server response headers.
Q43ExperiencedMost askedScenarioFree with sign-inAnswerHideHow do you handle a long-running operation in a REST API, such as generating a large report?
Do not keep the HTTP connection open. Use the asynchronous request-reply pattern.
Q44ExperiencedMost askedScenarioFree with sign-inAnswerHideWhat is the N+1 problem in APIs and how do you fix it?
The N+1 problem happens when you fetch a list and then run one extra query for each item to load related data. For example, 100 orders with their customers become 101 queries.
Q45ExperiencedMost askedScenarioFree with sign-inAnswerHideYour mobile app versions cannot be forced to update, but the API needs a breaking change. What do you do?
Keep old clients working while new ones move over.
Q46ExperiencedMost askedScenarioFree with sign-inAnswerHideHow would you design bulk operations, such as importing 10,000 users through an API?
Do not send 10,000 separate requests. Do not send one request that times out.