Status codes · 1xx–5xx
2xx: 200, 201, 202, 204, 205 and 206
Success, creation, acceptance, an empty body and partial content mean different things.
Understand the concept
200 means successful handling, with the representation determined by the method. A GET returns a representation, while a POST response may describe its processing result. 201 means creation of one or more resources. Identify the primary resource with Location, or otherwise the target URI. 202 means processing was accepted but has not finished, and may eventually fail. Design a separate monitoring contract.
204 and 205 do not carry response content. Use 204 when no representation is needed; 205 asks the user agent to reset the document view that initiated the request. Neither means an arbitrary empty collection. An unconditional response.json() on 204 will fail to parse. HEAD has its own no-content semantics.
206 serves an accepted byte range and needs the relevant range metadata. Other specialised success codes include transformed representations, WebDAV responses and delta encodings. Choose codes for their meaning, not their novelty, and distinguish transport success from completed business work.
When designing CRUD endpoints and asynchronous jobs.
Treating 202 as completed work or 204 as JSON null.
One topic. Three levels of depth.
HTTP/1.1 200 OK
Content-Type: application/json
[]An empty collection is a valid representation, not a missing resource.
This page does not send requests to external servers. Messages are readable HTTP/1.1 illustrations, not HTTP/2 or HTTP/3 wire dumps. example.test is reserved for examples. Run commands and JavaScript only in your own test environment; never publish real tokens or cookies.
Try it yourself first.
A successful DELETE returns no representation. What should the client do?
Show the solution and explanation
if (response.status === 204) return;Finish on 204 without calling response.json().