Contents

Web & Networking › HTTP

2xx Success Codes

200 OK, 201 Created, 204 No Content and friends.

Also known as: 200 OK, 201 Created, 204 No Content, success status codes

Status codes in the 2xx range mean the request succeeded. The specific code says how.

CodeNameTypical use
200OKa normal success; the response body has the result (GET, PUT, PATCH)
201Createda new resource was made, usually by POST; include a Location header pointing at it
202Acceptedthe request was received, but processing happens later (a background job)
204No Contentsuccess with nothing to return, often for DELETE or PUT
206Partial Contentpart of a resource, for range requests (video, resumable downloads)
POST /orders HTTP/1.1
...
HTTP/1.1 201 Created
Location: /orders/917
Content-Type: application/json

{"id": 917, "status": "pending"}
DELETE /orders/917
HTTP/1.1 204 No Content

Choosing well

  • Use 201 for creation, not 200, and return the new resource or its location.
  • Use 202 for asynchronous work, and tell the client how to check progress (a status URL) (long-running operations).
  • Don’t send a body with 204. By definition there is none.
  • Don’t return 200 with an error inside. If it failed, use a 4xx or 5xx code (status codes).
  • Be consistent across your API, so clients can rely on the codes.

For API clients

Treat any 2xx as success, not just 200: check for the range (res.ok in fetch) (fetch API). Then look at the specific code and body.

See also redirects (3xx), client errors (4xx) and server errors (5xx).