APIs & Protocols
API and protocol knowledge an analyst needs to write specs — HTTP structure and status codes, REST principles, API styles compared, data formats, and idempotency.
23 questions
JuniorTheoryVery commonHow do the HTTP methods GET, POST, PUT, and PATCH differ?
How do the HTTP methods GET, POST, PUT, and PATCH differ?
GET reads a resource: safe, cacheable, no body. POST creates or triggers an action and is not idempotent — repeating it creates duplicates. PUT fully replaces a resource and is idempotent. PATCH applies a partial update to some fields.
Common mistakes
- ✗Calling POST idempotent or PUT non-idempotent
- ✗Confusing PUT (full replace) with PATCH (partial update)
- ✗Forgetting GET is safe, cacheable, and body-less
Follow-up questions
- →Why is PUT idempotent but POST is not?
- →Which method would you choose to update a single field of a resource?
JuniorTheoryVery commonWhat is a RESTful application, and what does "stateless" mean for the server and the client?
What is a RESTful application, and what does "stateless" mean for the server and the client?
A RESTful application models data as resources addressed by URLs and driven by standard HTTP verbs. Stateless means the server keeps no session between calls — each request carries its own context, so the client resends it every time and any node can serve it.
Common mistakes
- ✗Thinking the server stores a per-client session
- ✗Believing the client may omit its context on later calls
- ✗Assuming only the original node can answer a client
Follow-up questions
- →How does statelessness help a REST API scale out?
- →Where is session-like data kept if not on the server?
JuniorTheoryVery commonWhich HTTP methods are safe and which are idempotent — is DELETE idempotent?
Which HTTP methods are safe and which are idempotent — is DELETE idempotent?
Safe methods don't change server state — GET, HEAD, OPTIONS. Idempotent methods leave the same end state on repeat — GET, PUT, DELETE. DELETE is idempotent — deleting twice leaves it gone, though the second call may return 404. POST is neither, so repeating it creates duplicates.
Common mistakes
- ✗Treating safe and idempotent as the same property
- ✗Claiming DELETE is not idempotent because of a later 404
- ✗Calling POST idempotent
Follow-up questions
- →Why does a repeated DELETE returning 404 still count as idempotent?
- →Can a safe method ever be non-idempotent?
JuniorTheoryVery commonWhat is the difference between 200, 201, 202 and 204 — and between 401 and 403?
What is the difference between 200, 201, 202 and 204 — and between 401 and 403?
200 OK — success with a body. 201 Created — a new resource exists, URL in Location. 202 Accepted — queued for async work, not done yet. 204 No Content — success, no body. 401 means not authenticated (log in); 403 means authenticated but lacking permission.
Common mistakes
- ✗Confusing 201 Created with a plain 200 OK
- ✗Using 200 where 202 (queued, async) is meant
- ✗Swapping 401 (not authenticated) and 403 (no permission)
Follow-up questions
- →Which code fits a long-running request that isn't done yet?
- →A logged-in user hits an admin route — 401 or 403?
JuniorTheoryCommonWhere do filtering, sorting and field selection go on a REST endpoint?
Where do filtering, sorting and field selection go on a REST endpoint?
All three go in the query string of the collection, not the path. Filter by field values — ?status=paid. Sort with a parameter — ?sort=-createdAt (minus for descending). Select fields to trim payload — ?fields=id,total. They compose on one GET /orders, keeping it cacheable.
Common mistakes
- ✗Baking filter or sort values into the resource path
- ✗Making each filter combination a separate endpoint
- ✗Thinking GET cannot carry query parameters
Follow-up questions
- →How would you express descending sort in the query string?
- →Why keep these in the query rather than the path?
JuniorTheoryCommonWhat is the structure of an HTTP request and response, and which classes of status codes do you know?
What is the structure of an HTTP request and response, and which classes of status codes do you know?
An HTTP request has a request line (method + URL), headers, and an optional body. A response has a status line, headers, and an optional body. Codes fall into five classes: 1xx informational, 2xx success, 3xx redirection, 4xx client errors, 5xx server errors.
Common mistakes
- ✗Forgetting headers or the body as parts of the message
- ✗Swapping the meaning of 4xx (client) and 5xx (server)
- ✗Not knowing the five status-code classes
Follow-up questions
- →What does status code 401 mean and how does it differ from 403?
- →Which class contains the code meaning "resource moved"?
JuniorTheoryCommonWhat is OpenAPI/Swagger, what does the spec contain, and who consumes it?
What is OpenAPI/Swagger, what does the spec contain, and who consumes it?
OpenAPI (formerly Swagger) is a machine-readable, language-agnostic description of a REST API in YAML or JSON. It lists every endpoint — paths, methods, parameters, schemas, status codes and auth. Tools consume it to render docs, generate client stubs, mock the API, or run contract tests.
Common mistakes
- ✗Thinking OpenAPI runs the API rather than describes it
- ✗Believing only humans (not tools) consume the spec
- ✗Forgetting the spec covers schemas, status codes and auth
Follow-up questions
- →Which tooling can generate from an OpenAPI file?
- →How does an OpenAPI spec support contract testing?
JuniorTheoryCommonWhich naming and structure conventions do you follow for REST resources?
Which naming and structure conventions do you follow for REST resources?
Name resources with plural nouns, not verbs — /orders, /orders/42/items. The verb is the HTTP method, so avoid /getOrder. Nest to show ownership but stay shallow; beyond that, link by id. Use lowercase with hyphens and keep the collection/item pattern predictable.
Common mistakes
- ✗Encoding the action as a verb in the path (
/getOrder) - ✗Nesting resources too deeply instead of linking by id
- ✗Using singular nouns or inconsistent casing
Follow-up questions
- →How would you express "the items of order 42" as a path?
- →Why keep the action out of the URL entirely?
JuniorTheoryCommonWhat do request headers carry, and which response headers matter in REST — Content-Type, Location, ETag?
What do request headers carry, and which response headers matter in REST — Content-Type, Location, ETag?
Headers carry message metadata, separate from the body. Request headers include Authorization (credentials) and Accept (desired format). Key REST response headers are Content-Type (the format), Location (URL of a new resource, with 201), and ETag (a version tag for caching).
Common mistakes
- ✗Confusing header metadata with the message body
- ✗Not knowing
Locationreturns a created resource's URL - ✗Forgetting
ETagdrives caching and conditional requests
Follow-up questions
- →Which header returns the URL of a newly created resource?
- →How does
ETaglet the client skip re-downloading a resource?
JuniorTheoryCommonWhat goes in a URL — path parameters versus query parameters — and when do you use each?
What goes in a URL — path parameters versus query parameters — and when do you use each?
Path parameters identify a specific resource in the path — /orders/42 addresses one order. Query parameters refine a collection request — filtering, sorting and pagination like ?status=paid&page=2. Mandatory identifiers go in the path, optional modifiers in the query.
Common mistakes
- ✗Putting a mandatory resource id into the query string
- ✗Sending filters or pagination as path segments
- ✗Assuming path and query parameters are interchangeable
Follow-up questions
- →Where would you put a search term over a large list?
- →Should an optional filter ever appear as a path segment?
MiddleDesignCommonDesign the REST API for an online bookstore's cart and checkout. A user browses books, adds and removes cart items, then checks out to create an order. Lay out the resources, the HTTP methods on each, and the status codes for the main success and error cases.
Design the REST API for an online bookstore's cart and checkout. A user browses books, adds and removes cart items, then checks out to create an order. Lay out the resources, the HTTP methods on each, and the status codes for the main success and error cases.
Resources are nouns — /books, /cart/items, /orders. GET /books lists (200), POST /cart/items adds (201), DELETE /cart/items/{id} removes (204), POST /orders checks out (201 with Location). Return 404 for a missing book, 409 for an empty cart, 422 for bad data. Checkout is POST — a non-idempotent create.
Common mistakes
- ✗Encoding actions as path verbs like
/addToCart - ✗Making checkout a GET or an idempotent PUT
- ✗Returning 200 or 500 where 201/404/409 fit
Follow-up questions
- →Why is checkout a POST and not a PUT?
- →Which status code fits adding an out-of-stock book?
MiddleTheoryCommonHow do you make POST idempotent — what is an idempotency key and where is it stored?
How do you make POST idempotent — what is an idempotency key and where is it stored?
POST is not idempotent, so a retry can create a duplicate. The client sends a unique idempotency key in a header; the server stores it with the first response and, on a retry, returns that stored result instead of acting again. Keys live in a fast store with a TTL.
Common mistakes
- ✗Expecting the server to generate the key instead of the client
- ✗Not persisting the key-to-response mapping for replays
- ✗Ignoring the key and creating a new resource each call
Follow-up questions
- →Why must the client, not the server, generate the key?
- →How long should a stored idempotency key be kept?
MiddleDesignCommonThe delivery team often receives duplicate orders. Why does this happen and how would you design a safeguard so the same order is not created twice?
The delivery team often receives duplicate orders. Why does this happen and how would you design a safeguard so the same order is not created twice?
Duplicates arise when a non-idempotent create (POST) is retried after a timeout or double-click — the request succeeded but the client never saw the response. The fix is an idempotency key the backend records, so a repeated key returns the original result.
Common mistakes
- ✗Blaming the database instead of a retried non-idempotent create
- ✗Skipping a unique request/idempotency key
- ✗Trusting the client and omitting server-side request validation
Follow-up questions
- →How does the backend use the idempotency key on a retry?
- →Why does a network timeout trigger a resend of the order?
MiddleDesignCommonDesign pagination for a large, growing collection — say a feed of millions of events. Explain how your scheme returns a page and the next page, and what goes wrong with plain offset/limit paging at page 10 000 or when rows are inserted between requests.
Design pagination for a large, growing collection — say a feed of millions of events. Explain how your scheme returns a page and the next page, and what goes wrong with plain offset/limit paging at page 10 000 or when rows are inserted between requests.
Prefer cursor (keyset) pagination — the client sends an opaque cursor for the last row seen and gets the next slice plus a nextCursor. Offset/limit degrades at high offsets — the DB scans and discards every skipped row, so page 10 000 is slow. It also skips or repeats rows on inserts, since offsets shift.
Common mistakes
- ✗Defaulting to offset/limit for deep, high-volume paging
- ✗Ignoring skipped or duplicated rows under concurrent inserts
- ✗Thinking a high offset costs the DB nothing to skip
Follow-up questions
- →Why does a large offset stay slow even with an index?
- →How does a cursor avoid skipping rows during inserts?
MiddleDesignCommonA payment endpoint must reject an order whose card has expired. The order is otherwise valid and the client will retry. Design the response — which HTTP status code you return, what the body contains, and whether the client should retry automatically or ask the user to act.
A payment endpoint must reject an order whose card has expired. The order is otherwise valid and the client will retry. Design the response — which HTTP status code you return, what the body contains, and whether the client should retry automatically or ask the user to act.
Return a 4xx client error, not a 5xx — nothing broke server-side. 422 fits — the request is well-formed but the card is expired. The body carries a machine code (card_expired), a message and the field. The client must not auto-retry the same card; it should ask the user for a new one.
Common mistakes
- ✗Using 5xx for a client-side (card) problem
- ✗Returning 200 or an empty body with no error code
- ✗Auto-retrying the same expired card instead of prompting
Follow-up questions
- →Why 422 rather than 400 for this case?
- →What lets the client act on the error programmatically?
MiddleTheoryCommonWhat is REST and which of its core principles do you know?
What is REST and which of its core principles do you know?
REST is an architectural style over HTTP — recommendations, not a protocol like SOAP. Its constraints are client–server separation, statelessness, cacheability, a uniform interface of resources and standard verbs, a layered system, and optional code-on-demand.
Common mistakes
- ✗Calling REST a protocol rather than an architectural style
- ✗Forgetting statelessness or the uniform interface constraint
- ✗Confusing REST constraints with SOAP's mandatory envelope
Follow-up questions
- →What does "statelessness" mean in practice for the server?
- →Why is REST called advisory rather than mandatory?
MiddleTheoryCommonCompare the API styles — SOAP, REST, gRPC, and GraphQL — and where each is appropriate.
Compare the API styles — SOAP, REST, gRPC, and GraphQL — and where each is appropriate.
SOAP is a strict XML protocol with XSD/WSDL contracts — formal but heavy. REST is a style over HTTP with standard verbs — simple and ubiquitous. gRPC uses protobuf over HTTP/2 with streaming — fast backend-to-backend. GraphQL queries one endpoint.
Common mistakes
- ✗Calling SOAP a style and REST a protocol (it is the reverse)
- ✗Attributing protobuf/HTTP-2 streaming to REST instead of gRPC
- ✗Forgetting GraphQL's single endpoint and field-level fetching
Follow-up questions
- →When would you prefer gRPC over REST?
- →What over-fetching problem does GraphQL solve?
MiddleTheoryCommonCan you use POST to read data and GET to create it? What breaks if you do?
Can you use POST to read data and GET to create it? What breaks if you do?
The server runs whatever handler you wire, but you break the verbs' contract. GET is safe and cacheable, so proxies and crawlers may prefetch or repeat it — a GET that creates data fires side effects and may be cached wrongly. POST is uncached, so reading with it loses caching. Verbs must mean what they say.
Common mistakes
- ✗Assuming the verb has no effect on caches or crawlers
- ✗Forgetting a creating GET can fire on prefetch or retry
- ✗Reading with POST and losing cacheability
Follow-up questions
- →Why is a creating GET dangerous with browser prefetch?
- →What caching benefit is lost by reading via POST?
MiddleTheoryCommonHow do you version an API, and which changes are backward-compatible versus breaking?
How do you version an API, and which changes are backward-compatible versus breaking?
Strategies — URI versioning (/v2/orders), a custom header, or media-type in Accept; URI is simplest, headers stay clean. Adding optional fields or endpoints is backward-compatible — clients ignore what they don't know. Removing or renaming a field, retyping, or tightening validation is breaking, forcing a new version.
Common mistakes
- ✗Calling a new required field backward-compatible
- ✗Treating any change, even additive, as breaking
- ✗Thinking clients auto-adapt to removed or renamed fields
Follow-up questions
- →Is adding a new required request field breaking? Why?
- →When would you pick header over URI versioning?
SeniorDesignCommonAn endpoint must return a report that takes about three minutes to build, and a synchronous request would time out at the gateway. Design the REST interaction so the client can start the job, learn when it is done, and fetch the result — describe the resources, status codes, and how the client checks progress without holding the connection open.
An endpoint must return a report that takes about three minutes to build, and a synchronous request would time out at the gateway. Design the REST interaction so the client can start the job, learn when it is done, and fetch the result — describe the resources, status codes, and how the client checks progress without holding the connection open.
Make it asynchronous. POST /reports starts the job, returning 202 with Location at /reports/{id}. The client polls GET /reports/{id}, getting 200 with a status (pending/running/done) while it builds. When ready it returns the result or a 303 to the result resource. This survives the gateway timeout.
Common mistakes
- ✗Keeping the call synchronous and fighting the gateway timeout
- ✗Re-POSTing the job instead of polling a job resource
- ✗Returning 200/500 instead of 202 plus a status resource
Follow-up questions
- →Why 202 and a
Locationrather than 200 with the report? - →How would the client know how long to wait between polls?
SeniorDesignCommonA mobile app shows "unknown error" for every failure because the API returns bare 500s with an HTML page or an empty body. Redesign the error contract so the client can tell the cases apart and act — distinguish a validation error, a missing resource, an auth problem, and a transient server fault, and say what the client should do for each.
A mobile app shows "unknown error" for every failure because the API returns bare 500s with an HTML page or an empty body. Redesign the error contract so the client can tell the cases apart and act — distinguish a validation error, a missing resource, an auth problem, and a transient server fault, and say what the client should do for each.
Return the right status class plus a consistent JSON body — a stable machine code, a human message, optional field details. Validation → 422 (fix input); missing → 404; auth → 401/403 (re-auth); transient → 503 with Retry-After (retry with backoff). The code drives client logic; the class says who is at fault and whether a retry helps.
Common mistakes
- ✗Using one status (500 or 400) for every failure kind
- ✗Returning HTML or an empty body instead of structured JSON
- ✗Omitting the stable code the client branches on
Follow-up questions
- →Which header tells the client when to retry a 503?
- →Why branch on a
coderather than on the message text?
JuniorTheoryOccasionalWhat data formats does an analyst need for specifications — JSON, YAML, XML, XSD, WSDL?
What data formats does an analyst need for specifications — JSON, YAML, XML, XSD, WSDL?
JSON is a text exchange format (json-schema describes its structure). YAML is human-readable, common in configs and specs. XML is verbose markup; XSD defines the allowed structure of an XML document, and WSDL describes a SOAP service's operations.
Common mistakes
- ✗Confusing what XSD describes (XML) with json-schema (JSON)
- ✗Treating WSDL as a data format rather than a service description
- ✗Thinking a format validates itself without a schema
Follow-up questions
- →How does XSD differ from WSDL?
- →When would you choose JSON versus XML for an integration?
MiddleTheoryOccasionalWhat are the Richardson maturity levels, and what does HATEOAS add?
What are the Richardson maturity levels, and what does HATEOAS add?
Richardson rates REST maturity in four levels. Level 0 — one URI, one verb. Level 1 — many resources, each a URI. Level 2 — proper verbs and status codes, where most APIs sit. Level 3 adds HATEOAS — responses embed links for the next actions, so the client navigates by those links.
Common mistakes
- ✗Not knowing most real APIs sit at level 2
- ✗Confusing HATEOAS with caching or authentication
- ✗Missing that HATEOAS means links drive navigation
Follow-up questions
- →Which level do most production REST APIs reach?
- →What practical benefit do embedded links give a client?