Card 09/ 09

RecapDifficulty: Intermediate1 min

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.
The four classes an API sends, against the catalogue's profile
ClassSaysCodes an API usesClient's next step
2xxIt worked200, 201, 202, 204Read the result, or check later on a 202
3xxLook elsewhere301, 302, 307, 308Follow Location
4xxThe request was wrong400, 401, 403, 404, 409, 422, 429Fix the request; retry only a 429, after waiting
5xxThe server failed500, 502, 503, 504Retry later, if repeating is safe