Card 09/ 09
Recap: HTTP Status Codes
The class says whose problem it is, and the code says what the client should do next.
A status code is the part of a response that software acts on.
- The first digit names the class, and a client that does not know a code treats it as the class's
x00. - 2xx says how it worked: 200 returned, 201 created, 202 accepted for later, 204 done with no body.
- 4xx says the request must change: the format, the address, the state, the values or the pace.
- 401 vs 403 is unknown caller against known caller refused; 404 hides that a resource exists.
- 5xx names where it failed: the application for 500, a gateway describing its upstream for 502 and 504.
- 307 and 308 keep the method on a redirect; 301 and 302 may turn a POST into a GET.
- An error inside a 200 is invisible to caches, monitoring and retries.
| Class | Says | Codes an API uses | Client's next step |
|---|---|---|---|
| 2xx | It worked | 200, 201, 202, 204 | Read the result, or check later on a 202 |
| 3xx | Look elsewhere | 301, 302, 307, 308 | Follow Location |
| 4xx | The request was wrong | 400, 401, 403, 404, 409, 422, 429 | Fix the request; retry only a 429, after waiting |
| 5xx | The server failed | 500, 502, 503, 504 | Retry later, if repeating is safe |
← → move through sections and cards