Quiz · Medium
Twenty-three questions on REST resource design, method semantics, status codes, caching with ETags, pagination, versioning, URLs and HTTP messages, and calling APIs with fetch.
Which URL and method best follow REST naming conventions for fetching all orders of user 42?
GET /getOrdersForUser?id=42
POST /users/42/getOrders
GET /users/42/orders
GET /user/42/order/list
REST URLs name resources with nouns and let the HTTP method carry the verb. GET /users/42/orders reads the orders collection of user 42. The other options put verbs or actions in the path, or misuse POST for a read.
A client POSTs a new user and the server creates it. Which response is most appropriate?
201 Created with a Location header pointing to the new user
200 OK with an empty body
204 No Content
302 Found redirecting to the login page
201 Created signals that a new resource exists, and Location tells the client where. 200 is acceptable in sloppy APIs but less precise; 204 gives no information about the new resource; 302 is a redirect.
A payment client retries PUT /orders/7 three times after timeouts. The server applies the update. What is the result?
Three updates are applied, charging three times
An error, because retries are forbidden
The server creates three orders
The same final state as one request, because PUT is idempotent
PUT replaces the resource with the supplied representation, so repeating it leaves the same state. POST would be the risky one. (The side effects of your own code, such as charging, still need care.)
In this URL diagram, what is the part ?color=red?
Fragment
Query string
Path
Scheme
The query string starts at ? and carries key=value pairs. The fragment starts at # and the path is /shoes.
True or false: the fragment (the part after #) is sent to the server in the HTTP request.
True
False
False. Browsers keep the fragment for themselves (scrolling to an element or client-side routing). Only the path and query reach the server.
In the HTTP message diagram, which element tells the receiver that the headers are over?
The status line
The Content-Type header
The body
A blank line
An empty line separates headers from the body. Content-Type describes the body but does not end the headers.
A client sends If-None-Match: "abc123", and the resource has not changed. What should the server reply?
304 Not Modified with no body
200 OK with the full body
204 No Content
412 Precondition Failed
The client holds a cached copy with ETag abc123. If it is still current, 304 lets the client reuse its copy and saves bandwidth. 412 is for failed If-Match/If-Unmodified-Since preconditions.
Which header value should be used for a response containing a user's bank statement that must never be stored in shared or browser caches?
Cache-Control: max-age=3600
Cache-Control: no-cache
Cache-Control: no-store
Cache-Control: public
no-store forbids storing the response. no-cache still lets caches store it and only requires revalidation before reuse; public and max-age encourage caching.
A social feed API has new posts inserted constantly. Which pagination style avoids duplicated or skipped items while scrolling?
Offset/limit with page numbers
Returning everything in one response
Random sampling
Cursor-based pagination (e.g. ?after=<last_id>)
With offset pagination, an insert between page loads shifts the rows and causes duplicates or gaps. A cursor anchors to a specific item, so the next page starts exactly after it.
Which change to an existing v1 API response is a breaking change?
Adding a new optional field nickname
Renaming the field email to emailAddress
Adding a new endpoint /v1/reports
Adding a new optional query parameter
Clients written against the old contract look for email, so renaming (or removing, or changing the type of) a field breaks them. Additive changes are normally safe.
What does HATEOAS add to a REST API?
Faster database queries
Encryption of the response body
Links in responses that tell clients which resources and actions are available next
Automatic API versioning
Hypermedia as the engine of application state means the server drives the client with links (next, cancel, pay) instead of the client hard-coding URLs. It is level 3 of the Richardson maturity model.
Which error response is best for a form submission whose email field is invalid?
400 or 422 with a JSON body that names the field and the problem
200 OK with the body error
500 Internal Server Error
404 Not Found
A client error status (400 Bad Request or 422 Unprocessable Content) plus a structured body lets the UI highlight the field. 200 hides the failure, 500 blames the server, and 404 means the resource does not exist.
A request starts generating a large report that takes about two minutes. What is the best REST response?
202 Accepted with a Location header for a status resource the client can poll
Hold the connection open for two minutes
200 OK with an empty body
301 Moved Permanently
202 means 'accepted but not finished'. The Location URL (/jobs/123) reports progress and eventually links to the result. Long-held connections hit proxy and client timeouts.
What is wrong with this code?
const res = await fetch('/api/users/999'); const user = await res.json();
fetch needs a callback instead of await
res.json() is synchronous
It does not check res.ok: a 404 or 500 response does not make fetch reject
fetch cannot call relative URLs
fetch rejects only on network failure, not on HTTP error statuses. Check res.ok (or the status) before parsing. res.json() returns a Promise, and relative URLs work in browsers.
Which request header tells the server which response formats the client can handle?
Content-Type
Accept
Authorization
Host
Accept (for example application/json) drives content negotiation. Content-Type describes the body that is being sent.
A client sends PATCH /users/42 with the JSON body {"email":"[email protected]"}. What happens to the user's name?
It is set to null
The request is rejected because name is missing
The user is deleted and recreated
It is unchanged, because PATCH sends only the fields to modify
PATCH is a partial update; omitted fields stay as they are. PUT would replace the whole representation, and a missing name would typically be treated as removed or invalid.
Which HTTP method is idempotent?
POST
PATCH, always
DELETE
None of them
DELETE is idempotent: deleting the same resource twice leaves the same final state (it may return 404 the second time, but the state is the same). POST is not, and PATCH is not guaranteed to be.
Two editors load a document with ETag v5. Editor A saves with If-Match: v5 and succeeds. Editor B then saves with If-Match: v5. What should B receive?
412 Precondition Failed
200 OK, overwriting A's change
204 No Content
301 Moved Permanently
The ETag is now v6, so B's precondition fails. 412 prevents the lost update; B must reload, merge and try again.
What is the main benefit of HTTP/2 over HTTP/1.1 for API-heavy pages?
It makes responses smaller by removing headers
It removes the need for TLS
It turns POST into GET
Many requests can be multiplexed over a single connection
HTTP/2 interleaves many streams on one TCP connection and compresses headers (HPACK), reducing connection overhead and head-of-line blocking at the HTTP level. Most browsers use it only over TLS, but it does not 'remove' TLS.
Which statement describes a violation of REST's statelessness constraint?
The client sends an auth token with every request
The server keeps per-client conversation state in memory and relies on it between requests
The API uses JSON
The server returns cache headers
Stateless means each request must contain all the information needed to process it. Server-side per-client conversation state ties a client to a particular server and breaks scaling.
An API exposes a single URL POST /api and the JSON body says {"action": "getUser", "id": 42}. Which Richardson maturity level is this?
Level 1
Level 0
Level 2
Level 3
Level 0 uses HTTP as a tunnel to a single endpoint (RPC style). Level 1 introduces separate resources, level 2 uses HTTP verbs and status codes properly, and level 3 adds hypermedia.
Why does a browser perform a DNS lookup before the HTTP request in this diagram?

To check that the server supports HTTPS
To download the page's CSS
To prove it is not a robot
To convert the host name into an IP address it can connect to
Network connections need an IP address. DNS resolves www.wikipedia.org to one; only then can the browser send the HTTP GET. Image: Michel Bakni, CC BY-SA 4.0, via Wikimedia Commons.
A client sends Content-Type: text/xml to an endpoint that only accepts JSON. Which status is the best fit?
415 Unsupported Media Type
404
401
301
415 says the server refuses the request because the body's media type is not supported. 404 would mean the resource is missing, 401 is about authentication.