What are common HTTP status codes returned by REST APIs?
The first digit of an HTTP status code tells the whole story: 2xx worked, 4xx the caller made a mistake, 5xx the server did.
Status codes are how a REST API reports the outcome of a request in a machine-readable way - the client checks the number before trusting the body. Reading the leading digit is the fast skill: 2xx means success, 4xx points the finger at the request (fix your input), 5xx points at the server (retry or report a bug).
| Code | Meaning |
|---|---|
| 200 | OK - Request succeeded |
| 201 | Created - Resource created |
| 204 | No Content - Success, no body |
| 400 | Bad Request - Invalid input |
| 401 | Unauthorized - Auth required |
| 404 | Not Found - Resource missing |
| 500 | Internal Server Error |
A couple of distinctions worth nailing down: return 201 (not 200) after a successful POST that creates something, and 204 when an action succeeded but there is nothing to send back, such as a DELETE. The 401 vs 404 choice matters too - 401 says "I don't know who you are, log in", whereas 404 says "that thing isn't here". Gotcha for fetch: the browser only rejects the Promise on a network failure; a 404 or 500 still resolves successfully, so you must inspect response.status (or response.ok) yourself.
Go deeper:
MDN: HTTP response status codes — the full catalogue grouped by the five leading-digit classes (1xx–5xx).