All specialtiesTechnology · Job interview

REST API

REST questions look simple, but good answers show real design judgement. Learn to explain verbs, status codes and safe retries in clear, short English.

Words → phrases → sentences → speaking

Try SpeakRole ↗
Job interviewREST API
V

How do you design a REST API that stays backward compatible?

0:18
Interviewer question

REST API

Interviewers use REST questions to see how you design an interface that other developers will use for years. They listen for correct HTTP semantics, but also for practical sense: errors that help the client, safe retries and changes that do not break existing users.

Answer with one concrete resource, such as orders, and keep using it. An example like a POST to slash orders is easier to say aloud and to follow than an abstract rule. Mention a trade-off whenever you give a rule, because REST has many "it depends" cases.

  • ✓Words → phrases → sentences → speaking
  • ✓Answer meaning
  • ✓Language

Common questions and sample answers

How do you design a REST API for a resource like orders, and when do you use PUT, PATCH and POST?

What the interviewer wants to hear. Nouns in URLs, HTTP methods with the right meaning, statelessness, and the difference between replacing and partially updating.

Sample answer to practise aloud

I model the resource as a noun, so I have slash orders for the collection and slash orders slash 123 for one order. The HTTP method carries the action. GET reads. POST creates a new order, and I return 201 with a Location header. PUT replaces the whole order, so sending the same request twice gives the same result. PATCH changes only some fields. DELETE removes the order. The server stays stateless: each request carries everything needed, including the authentication token. For actions that do not fit a resource, like cancelling an order, I can use a sub-resource, and I stay consistent.

Which HTTP status codes do you use, and how do you return errors?

What the interviewer wants to hear. The right families and specific codes (201, 204, 400, 401, 403, 404, 409, 429), plus one consistent error body.

Sample answer to practise aloud

I use the status code families on purpose. 2xx means success: 200 for a normal response, 201 for a created resource and 204 when there is nothing to return. 4xx means the client made a mistake: 400 for a bad request, 401 when the user is not authenticated, 403 when the user is known but not allowed, 404 when the resource is missing, 409 for a conflict, and 429 when the client sends too many requests. 5xx means our server failed. I return the same JSON error format everywhere: a code, a clear message and details for validation errors. I never show stack traces.

What is idempotency, and why does it matter for an API?

What the interviewer wants to hear. A precise definition, which methods are idempotent, and how to make a POST safe to retry, for example with an idempotency key.

Sample answer to practise aloud

An operation is idempotent when repeating it leaves the server in the same state as doing it once. GET, PUT and DELETE are idempotent by definition, while POST is not. This matters because networks fail. A client sends a payment request, gets a timeout and does not know if it worked. If it retries and the request is not idempotent, the customer may pay twice. For such cases I support an idempotency key: the client sends a unique key in a header, the server stores the key with the result, and a repeated request returns the saved result instead of doing the work again.

How do you implement pagination, and what is wrong with offset pagination?

What the interviewer wants to hear. Offset versus cursor pagination, the cost on large tables, consistency when data changes, and a maximum page size.

Sample answer to practise aloud

The simplest way is offset pagination: the client sends a limit and an offset. It is easy to use and allows jumping to a page. But it has two problems. On big tables, the database still has to skip all the earlier rows, so late pages become slow. And if rows are added or deleted while the client is reading, items can be skipped or repeated. For large or fast-changing data, I prefer cursor pagination. The client sends the cursor from the last item, usually based on a key such as the creation time and the ID, and the server returns the next items after it. In both cases I set a maximum page size.

How do you secure a REST API?

What the interviewer wants to hear. HTTPS, authentication versus authorisation, token-based access such as OAuth 2.0, and permission checks for each object.

Sample answer to practise aloud

First, everything runs over HTTPS. For authentication, I usually use tokens. With OAuth 2.0, a client gets a short-lived access token, often a JWT, and sends it in the Authorization header. A refresh token can get a new one. For server-to-server calls, an API key can identify the caller, but it is not a replacement for user permissions. After authentication, I check authorisation on the server for every request, including whether this user may access this specific object. A missing check there is a common vulnerability. I also validate the input, apply rate limiting and avoid putting tokens in URLs, because URLs end up in logs.

How to say the key terms

REST
rest
idempotent
eye-dem-POH-tent
endpoint
END-point
payload
PAY-lohd
pagination
pad-juh-NAY-shun
OAuth
OH-awth
JSON
JAY-son

Useful phrases for answering

  • I would model this as a resource.
  • The client can safely retry this request.
  • I would return a 409, because…
  • The response includes a link to the next page.
  • We keep the API backward compatible by…
  • The trade-off is simplicity against flexibility.
  • The server never trusts the client input.

Common mistakes to avoid

  • Putting verbs in URLs, such as "getOrders" or "deleteUser". Use nouns for resources and let the HTTP method describe the action. You can mention the rare exception for actions like "cancel".
  • Returning 200 for every response and putting the error in the body. Clients, proxies and monitoring rely on the status code, so use the correct one.
  • Confusing 401 and 403. 401 means "I do not know who you are", and 403 means "I know who you are, but you may not do this".
  • Saying that PUT and POST are the same. Explain that PUT replaces a known resource and can be repeated safely, while POST usually creates something and is not idempotent.
  • Avoiding the word "idempotent" or pronouncing it differently each time. Say it slowly once: eye-dem-POH-tent. It is a key word in this topic.

Frequently asked questions

Is REST the same as an HTTP API with JSON?

Not exactly. REST is an architectural style with ideas such as resources, statelessness and a uniform interface. Many "REST" APIs follow only part of it, and you can say so honestly: "we build resource-oriented HTTP APIs with JSON".

How do I talk about API versioning?

Say that you try to avoid breaking changes: you add fields instead of removing or renaming them. When a break is unavoidable, you introduce a new version, most often in the URL or in a header, support the old one for an agreed period and tell clients early.

Should I mention OpenAPI or Swagger?

Yes, if you used them. A written contract in OpenAPI helps teams agree before coding, produces documentation and can help generate client code and tests. Say how your team kept the contract and the code in sync.

Reading an answer is not the same as saying it. Practise each question out loud, then compare the meaning and the language of your own answer.

Try SpeakRole ↗

Other topics in this area