HTTP & APIs Interview Questions
Reviewed by Mark Dickie · Last updated
HTTP is the application-layer protocol that carries nearly all web traffic, and APIs are the contracts built on top of it that let systems exchange data. For an interview on HTTP and APIs, you need to know the request/response lifecycle, common methods and their semantics, status code families, authentication schemes, caching directives, and the differences between REST, GraphQL, and RPC. Most questions will test whether you can reason about these mechanisms under real conditions rather than recite definitions.
What does an HTTP & APIs interview test?
Interviewers tend to probe four areas: protocol mechanics, API design trade-offs, security, and performance. The table below maps each area to what you should be ready to explain:
| Area | What gets asked |
|---|---|
| Protocol mechanics | Methods, status codes, headers, idempotency, content negotiation |
| API design | REST resource modeling, versioning, pagination, error formats, GraphQL vs REST |
| Security | OAuth 2.0 flows, API keys, JWT structure, CORS, TLS |
| Performance | Caching headers (Cache-Control, ETag), conditional requests, compression, keep-alive |
How should you approach HTTP method and status code questions?
These are the most common opening questions. Be precise about semantics:
- Know which methods are safe (
GET,HEAD,OPTIONS), which are idempotent (PUT,DELETEin addition to safe methods), and which are neither (POST,PATCHin some interpretations). - Memorize the status code ranges: 2xx success, 3xx redirection, 4xx client errors, 5xx server errors. Be ready to pick between close neighbors like
401vs403or409vs422. - Understand content negotiation through the
AcceptandContent-Typeheaders, including how a server picks a representation from multiple acceptable types. - Be able to explain what happens during a redirect chain and when
301vs302vs307vs308matters for method preservation.
What API design topics come up most?
REST resource naming and relationship modeling show up often. You should be able to design a set of endpoints for a given domain, decide between nested and flat resource paths, and justify your pagination strategy (offset vs cursor). Versioning strategy is another frequent topic: path-based (/v1/), header-based, and query-parameter approaches each have trade-offs worth articulating. GraphQL questions usually center on when its single-endpoint, client-driven query model is preferable to multiple REST calls and what problems it introduces (query complexity, caching difficulty).
What should you know about API authentication?
Expect to describe at least two of these flows end to end:
- API key — a static token passed in a header or query parameter; simple but hard to revoke selectively and exposed in logs if placed in the URL.
- OAuth 2.0 authorization code flow — the redirect-based flow used by most web apps; know the roles of the authorization server, resource server, client, and resource owner.
- JWT — the three-part structure (header, payload, signature), how verification works, and why you should never put secrets in the payload.
- mTLS — mutual certificate authentication used in high-trust service-to-service communication.
How does HTTP caching work in practice?
Caching questions test whether you understand the interaction between Cache-Control directives, ETag validators, and conditional requests. Know the difference between public and private, what max-age and s-maxage control, and how must-revalidate changes stale behavior. A common scenario question gives you a caching header configuration and asks what a browser vs a CDN will do on the second request. Be ready to trace a conditional GET with If-None-Match through to a 304 Not Modified response.
Key facts
- Tarmac has 116 HTTP & APIs interview questions on this topic, 10 of them on this page, at difficulty 2–5 of 5.
- Tarmac last reviewed these HTTP & APIs interview questions on 18 August 2026.
At a glance
| Questions | 10 shown · 116 in the bank |
|---|---|
| Difficulty | 2–5 of 5 |
| Formats | Find the bug, Flashcard, Fill in the blank, Multiple choice, Multiple answer, Ordering, Short answer, Code output, True / false |
What you'll review
- status codes
- cookies sessions
- oauth basics
- webhooks
- api design
- rate limiting
Practice questions
HTTP & APIs/http-protocol/status-codes
This Express handler creates a new user. From an HTTP-semantics standpoint, what is wrong with the response?#
app.post("/users", async (req, res) => {
const user = await db.users.create(req.body);
res.status(200).json(user);
});Options
Show answer
It should respond 201 Created (ideally with a Location header), not 200 OK, because a new resource was created
When a request creates a new resource the correct status is 201 Created, and best practice is to include a Location header (e.g. /users/{id}) pointing at it (RFC 9110 §15.3.2). POST is a perfectly valid way to create a subordinate resource, returning the representation in the body is fine, and 204 would be wrong because there is a body to send.
HTTP & APIs/api-auth/cookies-sessions
What does the HttpOnly attribute on a Set-Cookie header do, and why use it for session cookies?#
Show answer
HttpOnly makes the cookie inaccessible to client-side JavaScript (document.cookie); it is only sent automatically on HTTP requests. Setting it on a session cookie blunts XSS attacks, because injected script cannot read or exfiltrate the session token. Pair it with Secure (HTTPS only) and SameSite (CSRF mitigation).
HttpOnly is a core defence for session cookies: even if an attacker injects script via XSS, they cannot steal the cookie through the DOM. It does not prevent the cookie from being sent, so SameSite and CSRF tokens remain necessary for cross-site request protection.
HTTP & APIs/api-auth/oauth-basics
Complete the following statements about OAuth 2.0 token types and the state parameter:#
Show answer
Complete the following statements about OAuth 2.0 token types and the state parameter:
- An access token is typically short-lived (lasting minutes to hours), while a refresh token is typically long-lived (lasting days to months) and is used to obtain new access tokens without re-involving the user.
- The
stateparameter in the authorization request is an opaque value the client generates and later verifies in the callback response, primarily to prevent CSRF attacks.
Access tokens are intentionally short-lived to limit the damage window if they are compromised; once expired, the client must use a long-lived refresh token to get a new one without forcing the user to log in again. The state parameter acts as a CSRF mitigation: the client stores it locally (e.g., in session or a cookie), includes it in the authorization request, and then verifies that the value returned in the callback matches—preventing a malicious site from tricking the client into completing an authorization flow it did not initiate.
HTTP & APIs/api-design/webhooks
You are designing a webhook consumer endpoint that receives order-created events from a third-party payment provider. The provider retries delivery up to 5 times with exponential back-off if it does not receive an HTTP 2xx within 10 seconds. Processing each event involves writing to a database and sending an email, which can take up to 30 seconds.#
Options
Show answer
The correct strategy is to verify the webhook's HMAC signature, persist the raw payload to a durable queue or store, return 200 OK right away, and process the event asynchronously — using the event ID to deduplicate before taking any action. This matters because the provider expects a 2xx within its 10-second timeout window, but the actual work (database write, email send) can take up to 30 seconds. If you do that work synchronously, the provider times out and retries, producing duplicate deliveries. Storing the raw payload first and processing it later is the standard accept-then-process pattern; checking the event ID before acting prevents duplicate side effects across retries.
Webhook reliability requires the consumer to respond quickly (within the provider's timeout window, often 5–30 s) with a 2xx status to acknowledge receipt, then process asynchronously. If the consumer does heavy work synchronously and times out, the provider may retry, causing duplicate deliveries. Idempotency keys/event IDs let consumers deduplicate retries. Signature verification (HMAC) guards against spoofed payloads but does not help with duplicate delivery. Storing the raw payload before processing is the correct 'accept-then-process' pattern. Option C describes returning a 200 immediately and queuing the work — the correct pattern — while the others describe anti-patterns or incomplete solutions.
HTTP & APIs/api-design/webhooks
You are building a webhook producer system that notifies registered consumers of payment.succeeded events. Select all statements that represent established best practices for a production-grade webhook producer.#
Options
Pick every one that applies.
Show answer
- Include a unique, immutable
event_idin every webhook payload so consumers can implement idempotent processing. - Sign each payload with HMAC-SHA256 using a per-consumer secret and include the signature in a request header (e.g.,
X-Signature) so consumers can verify authenticity. - Retry failed deliveries using exponential back-off with jitter, and stop after a configurable maximum number of attempts, notifying the consumer owner of persistent failures.
A robust webhook producer must handle consumer-side failures gracefully. The correct practices are: (1) retry with exponential back-off and jitter to avoid thundering-herd effects, (2) include a unique, stable event ID so consumers can deduplicate, (3) sign payloads (e.g., HMAC-SHA256) so consumers can verify authenticity, and (4) emit a full event envelope rather than just an identifier (although 'thin' notification + fetch is a valid alternative pattern). Delivering from a single IP without fallback, expecting synchronous processing in under 1 s, and omitting signatures are all anti-patterns. Options A, C, and D are all correct best practices; B (delivering only to a fixed IP with no retry) is not a best practice.
HTTP & APIs/api-design/webhooks
Place the following steps of inbound webhook request handling in the correct order, from first to last, for a secure and reliable consumer implementation:#
Put these in order
Show answer
- Read and buffer the raw request body bytes (before any JSON parsing).
- Compute and verify the HMAC-SHA256 signature over the raw body using the shared consumer secret; reject with
401if invalid. - Deserialize / parse the verified JSON payload into a domain object.
- Check the event ID against a store of already-processed IDs to ensure idempotent handling.
- Enqueue the event for asynchronous processing and return
200 OKto the provider.
The ordering question covers the correct sequence for securely and reliably processing an inbound webhook. You must first read and buffer the raw body before any parsing so the HMAC can be computed over the exact bytes the sender signed. Next you verify the HMAC signature against the raw body — rejecting with 401/403 if invalid — before trusting any data. Then you parse/deserialize the verified payload. After that you perform idempotency check using the event ID so duplicate retries are ignored. Finally you enqueue the work for async processing and return 200 OK. Reversing signature verification and parsing, or checking idempotency before verifying authenticity, are both security or correctness errors.
HTTP & APIs/api-design
You are designing a REST API endpoint that allows a client to partially update a resource. The client wants to update only the email field of a user without touching any other fields. Explain which HTTP method you should use, why it is preferred over the alternative update method for this use case, and what a minimal correct request would look like (method, path, and body).#
Show answer
Use PATCH instead of PUT. PUT is meant for full replacement of a resource — the client must send the complete representation, and any omitted fields may be set to null or cause errors. PATCH is designed for partial updates: the client sends only the fields it wants to change. A correct request would be: PATCH /users/42 with body {"email": "[email protected]"}. The server applies only that change, leaving all other fields intact.
PATCH is the semantically correct method for partial updates per RFC 5789. PUT implies a complete replacement of the resource at the given URI; sending a partial body with PUT can lead to data loss or implementation-specific behavior. PATCH lets clients send a diff/patch document (often just a JSON subset) so only specified fields are changed. Strong candidates also note that PUT is idempotent and PATCH may be idempotent depending on the patch semantics, and that the server should return 200 or 204 on success.
HTTP & APIs/api-auth/oauth-basics
An OAuth 2.0 authorization server issues tokens with the following JWT payload:#
Options
Show answer
The resource server must reject the token with HTTP 401 and WWW-Authenticate: Bearer error="invalid_token" because the exp claim has elapsed. RFC 7519 §4.1.4 states JWT processors MUST reject tokens where the current time is at or after exp. RFC 6750 §3.1 mandates the 401 + invalid_token response. There is no mandatory default clock-skew tolerance defined by the spec.
RFC 7519 §4.1.4 mandates that JWT processors MUST reject tokens where the current time is at or after the exp value. RFC 6750 §3.1 specifies that an expired token is an invalid_token error and the resource server MUST respond with HTTP 401 and a WWW-Authenticate header carrying error="invalid_token". The azp claim (authorized party) is checked by the client, not required by the resource server for basic validation. The aud as a URI is perfectly valid per RFC 7519 §4.1.3. RFC 7519 does acknowledge that implementors may allow small clock skew, but it is not a default tolerance, and 'MUST reject' takes precedence — accepting is never the correct answer once past exp.
HTTP & APIs/api-security/rate-limiting
A Node.js API gateway uses the following sliding-window rate-limiter logic. Given that the current Unix timestamp is 1000 seconds and the client has prior request timestamps of [994, 996, 998, 999] stored in a sorted set, what does the function log when a new request arrives at t = 1000 with a 5-second window and a limit of 4 requests?#
function checkRateLimit(timestamps, now, windowSecs, limit) {
const windowStart = now - windowSecs; // 1000 - 5 = 995
const recent = timestamps.filter(t => t > windowStart);
if (recent.length >= limit) {
const retryAfter = windowSecs - (now - recent[0]);
console.log(`429 Too Many Requests. Retry-After: ${retryAfter}s`);
} else {
recent.push(now);
console.log(`200 OK. Requests in window: ${recent.length}`);
}
}
checkRateLimit([994, 996, 998, 999], 1000, 5, 4);Options
Show answer
200 OK. Requests in window: 4
windowStart = now - windowSecs = 1000 - 5 = 995. The filter t > 995 (strictly greater than) drops 994 (which equals 995 − 1, not strictly greater) and keeps [996, 998, 999] — that is 3 entries. Since 3 < 4 (the limit), the if branch is not taken; the else branch runs, pushes 1000 onto recent making its length 4, and logs 200 OK. Requests in window: 4. Option (b) would be the output only if all four prior timestamps were in-window (i.e., recent.length >= 4 before the push), but that is not the case here because 994 is excluded by the strict > comparison.
HTTP & APIs/api-design
HTTP/2 multiplexing completely eliminates head-of-line (HOL) blocking for all requests sharing a single connection, including scenarios involving packet loss at the TCP layer.#
Options
Show answer
False. HTTP/2 multiplexing eliminates HOL blocking at the HTTP layer by interleaving frames from multiple streams on one connection, but TCP's own HOL blocking remains: a single lost packet stalls every stream on that connection until it is retransmitted. HTTP/3 (QUIC over UDP) is what actually addresses the TCP-level HOL problem.
HTTP/2 multiplexing eliminates head-of-line blocking at the HTTP layer by allowing multiple streams over a single TCP connection. However, TCP itself still suffers from head-of-line blocking at the transport layer — a single lost packet stalls all streams on that connection. HTTP/3 (QUIC) solves this by operating over UDP with per-stream loss recovery. The statement that HTTP/2 fully eliminates head-of-line blocking is therefore false; it only solves it at the application layer, not the transport layer.
Sources
The official documentation these questions are checked against:
Related interview questions
The other 106 questions
This page shows 10. A free account opens the rest and marks your answers, which a page of answers can't do. Miss one and it returns a few days later, then a week after that, until you stop missing it.
Free · the whole bank · 100 graded answers per 30 days · written feedback and job-ad quizzes on the paid plan