REST API interview questions: answers with real responses
Methods, status codes and API design questions, each answered in plain words and shown with a real request and response.
REST API interviews test HTTP itself: which methods are safe and idempotent, PUT vs POST, the right status codes (201, 204, 400, 401, 403, 404, 405), how to report errors, caching with ETags, pagination and safe retries. Below are 12 questions; every example calls a small sample API and shows the real status, headers and body it returned.
The small API every example calls
A minimal jobs API written with Python's standard library. It starts fresh on 127.0.0.1 for each example; call() prints the method, path, status code, key headers and body the client received.
import json, threading, http.server, urllib.request, urllib.error
JOBS = {1: {"id": 1, "title": "Data Analyst", "version": 1}, 2: {"id": 2, "title": "QA Engineer", "version": 1}}
NEXT = [3]
class API(http.server.BaseHTTPRequestHandler):
def log_message(self, *a): pass
def send(self, code, body=None, headers=None, ctype="application/json"):
data = b"" if body is None else json.dumps(body).encode()
self.send_response(code)
for k, v in (headers or {}).items(): self.send_header(k, v)
if body is not None: self.send_header("Content-Type", ctype)
self.send_header("Content-Length", str(len(data))); self.end_headers(); self.wfile.write(data)
def problem(self, code, title, detail):
self.send(code, {"type": "about:blank", "title": title, "status": code, "detail": detail}, ctype="application/problem+json")
def job_id(self):
parts = self.path.split("?")[0].strip("/").split("/")
return int(parts[1]) if len(parts) == 2 and parts[1].isdigit() else None
def body(self):
n = int(self.headers.get("Content-Length") or 0)
try: return json.loads(self.rfile.read(n) or b"{}")
except ValueError: return None
def do_GET(self):
if self.path.startswith("/jobs") and self.job_id() is None:
q = dict(p.split("=") for p in self.path.partition("?")[2].split("&") if "=" in p)
items = sorted(JOBS.values(), key=lambda j: j["id"]); lim, off = int(q.get("limit", 10)), int(q.get("offset", 0))
return self.send(200, {"items": items[off:off + lim], "total": len(items), "limit": lim, "offset": off})
j = JOBS.get(self.job_id())
if not j: return self.problem(404, "Not Found", f"no job {self.job_id()}")
etag = f'"v{j["version"]}"'
if self.headers.get("If-None-Match") == etag: return self.send(304, headers={"ETag": etag})
self.send(200, j, {"ETag": etag})
def do_POST(self):
b = self.body()
if b is None or not b.get("title"): return self.problem(400, "Bad Request", "title is required")
jid = NEXT[0]; NEXT[0] += 1; JOBS[jid] = {"id": jid, "title": b["title"], "version": 1}
self.send(201, JOBS[jid], {"Location": f"/jobs/{jid}"})
def do_PUT(self):
jid, b = self.job_id(), self.body()
if jid is None: return self.send(405, {"error": "use /jobs/{id}"}, {"Allow": "GET, POST"})
if b is None or not b.get("title"): return self.problem(400, "Bad Request", "title is required")
old = JOBS.get(jid)
same = old is not None and old["title"] == b["title"]
JOBS[jid] = {"id": jid, "title": b["title"], "version": old["version"] if same else (old["version"] + 1 if old else 1)}
self.send(200 if old else 201, JOBS[jid])
def do_DELETE(self):
jid = self.job_id()
if jid is None: return self.send(405, {"error": "use /jobs/{id}"}, {"Allow": "GET, POST"})
if JOBS.pop(jid, None) is None: return self.problem(404, "Not Found", f"no job {jid}")
self.send(204)
srv = http.server.ThreadingHTTPServer(("127.0.0.1", 0), API); threading.Thread(target=srv.serve_forever, daemon=True).start()
BASE = f"http://127.0.0.1:{srv.server_address[1]}"
def call(method, path, body=None, headers=None, show=("Location", "ETag", "Allow", "Content-Type")):
data = None if body is None else json.dumps(body).encode()
req = urllib.request.Request(BASE + path, data=data, method=method, headers={"Content-Type": "application/json", **(headers or {})})
try: r = urllib.request.urlopen(req); code, hdrs, raw = r.status, r.headers, r.read()
except urllib.error.HTTPError as e: code, hdrs, raw = e.code, e.headers, e.read()
line = f"{method} {path} -> {code}"
extra = [f"{h}: {hdrs[h]}" for h in show if hdrs.get(h)]
print(" ".join([line] + extra))
if raw: print(" ", raw.decode())
Basic rest api interview questions
Basic1. What makes an API RESTful in practice?
Resources are identified by URLs (/jobs, /jobs/2), clients act on them with standard HTTP methods, and the server reports the outcome with status codes. Each request carries everything the server needs, so the server does not keep session state between calls.
Pythoncall('GET', '/jobs/2')
call('GET', '/jobs?limit=1')Output (Python 3.12.10)GET /jobs/2 -> 200 ETag: "v1" Content-Type: application/json
{"id": 2, "title": "QA Engineer", "version": 1}
GET /jobs?limit=1 -> 200 Content-Type: application/json
{"items": [{"id": 1, "title": "Data Analyst", "version": 1}], "total": 2, "limit": 1, "offset": 0}Basic2. Which HTTP methods are safe, and why does it matter?
Safe methods (GET, HEAD, OPTIONS) are read-only by definition, so crawlers, caches and retries can call them without changing data. Using GET for an action that deletes or changes something breaks that assumption.
Pythoncall('GET', '/jobs/1')
call('GET', '/jobs/1')
print('unchanged:', JOBS[1])Output (Python 3.12.10)GET /jobs/1 -> 200 ETag: "v1" Content-Type: application/json
{"id": 1, "title": "Data Analyst", "version": 1}
GET /jobs/1 -> 200 ETag: "v1" Content-Type: application/json
{"id": 1, "title": "Data Analyst", "version": 1}
unchanged: {'id': 1, 'title': 'Data Analyst', 'version': 1}Checked against: RFC 9110: HTTP Semantics (IETF)
Basic3. What status code should a successful POST return?
201 Created when the POST creates a resource, with a Location header pointing at it. 200 is for success with a body that is not a new resource, and 204 for success with no body.
Pythoncall('POST', '/jobs', {'title': 'Support Engineer'})Output (Python 3.12.10)POST /jobs -> 201 Location: /jobs/3 Content-Type: application/json
{"id": 3, "title": "Support Engineer", "version": 1}Checked against: RFC 9110: HTTP Semantics (IETF)
Basic4. What does 204 No Content mean?
The request succeeded and there is deliberately no response body, which is common for DELETE. A client should not try to parse a body from a 204.
Pythoncall('DELETE', '/jobs/2')
call('GET', '/jobs/2')Output (Python 3.12.10)DELETE /jobs/2 -> 204
GET /jobs/2 -> 404 Content-Type: application/problem+json
{"type": "about:blank", "title": "Not Found", "status": 404, "detail": "no job 2"}Checked against: RFC 9110: HTTP Semantics (IETF)
Intermediate rest api interview questions
Intermediate5. What is the difference between PUT and POST?
POST asks the server to create something under a collection, and the server picks the new id. PUT sends the full state for a known URL and creates or replaces it. Repeating a PUT gives the same result; repeating a POST creates duplicates.
Pythoncall('PUT', '/jobs/9', {'title': 'SRE'})
call('PUT', '/jobs/9', {'title': 'SRE'})
call('POST', '/jobs', {'title': 'SRE'})
call('POST', '/jobs', {'title': 'SRE'})
print('jobs now:', sorted(JOBS))Output (Python 3.12.10)PUT /jobs/9 -> 201 Content-Type: application/json
{"id": 9, "title": "SRE", "version": 1}
PUT /jobs/9 -> 200 Content-Type: application/json
{"id": 9, "title": "SRE", "version": 1}
POST /jobs -> 201 Location: /jobs/3 Content-Type: application/json
{"id": 3, "title": "SRE", "version": 1}
POST /jobs -> 201 Location: /jobs/4 Content-Type: application/json
{"id": 4, "title": "SRE", "version": 1}
jobs now: [1, 2, 3, 4, 9]Checked against: RFC 9110: HTTP Semantics (IETF)
Intermediate6. What does idempotent mean, and which methods are idempotent?
A method is idempotent when sending the same request several times has the same effect on the server as sending it once. GET, PUT and DELETE are idempotent; POST is not. In the example, the second DELETE returns 404 because the job is already gone, and DELETE is still idempotent: RFC 9110 defines idempotency by the intended effect on the server, and the job stays deleted either way; the response code is not part of that definition. Idempotency is what makes automatic retries safe.
Pythoncall('DELETE', '/jobs/1')
call('DELETE', '/jobs/1')
print('job 1 present:', 1 in JOBS)Output (Python 3.12.10)DELETE /jobs/1 -> 204
DELETE /jobs/1 -> 404 Content-Type: application/problem+json
{"type": "about:blank", "title": "Not Found", "status": 404, "detail": "no job 1"}
job 1 present: FalseChecked against: RFC 9110: HTTP Semantics (IETF)
Intermediate7. What is the difference between 400, 401, 403 and 404?
400 means the request itself is wrong (missing or malformed data). 401 means the client is not authenticated, and 403 means it is authenticated but not allowed. 404 means the resource was not found, or the server chooses not to reveal that it exists.
Pythoncall('POST', '/jobs', {'company': 'Acme'})
call('GET', '/jobs/404')Output (Python 3.12.10)POST /jobs -> 400 Content-Type: application/problem+json
{"type": "about:blank", "title": "Bad Request", "status": 400, "detail": "title is required"}
GET /jobs/404 -> 404 Content-Type: application/problem+json
{"type": "about:blank", "title": "Not Found", "status": 404, "detail": "no job 404"}Checked against: RFC 9110: HTTP Semantics (IETF)
Intermediate8. When do you return 405, and what must it include?
405 Method Not Allowed means the server knows the method but this resource does not support it. The response must include an Allow header listing the methods the resource does support.
Pythoncall('DELETE', '/jobs')Output (Python 3.12.10)DELETE /jobs -> 405 Allow: GET, POST Content-Type: application/json
{"error": "use /jobs/{id}"}Checked against: RFC 9110: HTTP Semantics (IETF)
Intermediate9. How should an API report errors?
Use the right status code plus a consistent, machine-readable body. RFC 9457 defines a standard format, problem details, served as application/problem+json with fields such as type, title, status and detail.
Pythoncall('GET', '/jobs/77')Output (Python 3.12.10)GET /jobs/77 -> 404 Content-Type: application/problem+json
{"type": "about:blank", "title": "Not Found", "status": 404, "detail": "no job 77"}Checked against: RFC 9457: Problem Details for HTTP APIs (IETF)
Advanced rest api interview questions
Advanced10. How does caching with ETag and If-None-Match work?
The server sends an ETag that identifies the current version. The client sends it back in If-None-Match; if nothing has changed the server answers 304 Not Modified with no body, saving bandwidth. After an update the ETag changes and the client gets the new version.
Pythoncall('GET', '/jobs/1')
call('GET', '/jobs/1', headers={'If-None-Match': '"v1"'})
call('PUT', '/jobs/1', {'title': 'Senior Data Analyst'})
call('GET', '/jobs/1', headers={'If-None-Match': '"v1"'})Output (Python 3.12.10)GET /jobs/1 -> 200 ETag: "v1" Content-Type: application/json
{"id": 1, "title": "Data Analyst", "version": 1}
GET /jobs/1 -> 304 ETag: "v1"
PUT /jobs/1 -> 200 Content-Type: application/json
{"id": 1, "title": "Senior Data Analyst", "version": 2}
GET /jobs/1 -> 200 ETag: "v2" Content-Type: application/json
{"id": 1, "title": "Senior Data Analyst", "version": 2}Checked against: RFC 9110: HTTP Semantics (IETF)
Advanced11. How do you paginate a large collection?
Return a page of items with the information needed to fetch the next one: limit and offset (as here), or a cursor that points past the last item. Cursors stay stable when items are added during paging; offsets can skip or repeat items.
Pythoncall('GET', '/jobs?limit=1&offset=0')
call('GET', '/jobs?limit=1&offset=1')Output (Python 3.12.10)GET /jobs?limit=1&offset=0 -> 200 Content-Type: application/json
{"items": [{"id": 1, "title": "Data Analyst", "version": 1}], "total": 2, "limit": 1, "offset": 0}
GET /jobs?limit=1&offset=1 -> 200 Content-Type: application/json
{"items": [{"id": 2, "title": "QA Engineer", "version": 1}], "total": 2, "limit": 1, "offset": 1}Advanced12. How do you make POST safe to retry?
POST is not idempotent, so a retry after a timeout can create a duplicate. A common fix is an idempotency key: the client sends a unique key with the request and the server returns the stored result when it sees the same key again. This sample API has no such key, which is why two identical POSTs below create two jobs.
Pythoncall('POST', '/jobs', {'title': 'Recruiter'})
call('POST', '/jobs', {'title': 'Recruiter'})
print('recruiter jobs:', sum(1 for j in JOBS.values() if j['title'] == 'Recruiter'))Output (Python 3.12.10)POST /jobs -> 201 Location: /jobs/3 Content-Type: application/json
{"id": 3, "title": "Recruiter", "version": 1}
POST /jobs -> 201 Location: /jobs/4 Content-Type: application/json
{"id": 4, "title": "Recruiter", "version": 1}
recruiter jobs: 2Checked against: RFC 9110: HTTP Semantics (IETF)
How to practice with this page
- Before reading each output, say which status code you expect and why.
- Use the standard (RFC 9110) wording for safe and idempotent: interviewers notice precision.
- Copy the sample API and add PATCH or authentication to practice follow-up questions.
- Testers: turn each example into a test case with an expected status and body.
Related interview prep and tools
Back-end JavaScript with real output.
Open →QuestionsPython interview questionsCore language questions with real output.
Open →QuestionsSystem design interview questionsAPIs at scale: caching, queues and trade-offs.
Open →MethodSTAR methodStructure answers about projects and problems you solved.
Open →Free toolResume summary generatorDraft a summary for a Software Engineer role; the title is filled in, you add your experience.
Open →Free toolLinkedIn headline generatorWrite a headline for a Software Engineer search.
Open →Disclosure: TryHired makes HIRED, a paid job-search program, so we have a conflict of interest when we mention it. This question bank is free, with no TryHired signup.
Questions people ask
What REST API questions come up often in interviews?
Is REST the same as HTTP?
Do I need to write code to answer REST API questions?
How this page is built
TryHired wrote these questions and answers. Every code block on this page was executed with Python 3.12.10 when the page was built (2026-11-15), and the output shown is the real output; the build stops if any example fails. The question list is general practice: it does not predict what a particular employer will ask.
- Interviewers ask different questions for different roles and levels.
- Answers are short explanations, not complete references.
- The sample API is deliberately small: real APIs add authentication, validation libraries, rate limiting and versioning, which are explained but not all demonstrated here.
- RFC 9110: HTTP Semantics (IETF) (read 2026-11-15)
- RFC 9457: Problem Details for HTTP APIs (IETF) (read 2026-11-15)