Interpret HTTP status codes in context
Use the status class for orientation, then the exact code and request method for the response meaning.
- status codes
- responses
A status code reports the result of one request
The three-digit status code is response control data. Its first digit defines a class; the remaining digits identify the exact registered or extension code. The class helps you orient yourself, but clients act on the meaning of the complete code.
1xxis informational and precedes a final response.2xxmeans the request was successfully received, understood, and accepted.3xxcovers redirection and conditional reuse choices.4xxindicates that the client request cannot be fulfilled as sent.5xxindicates that the server failed while handling an apparently valid request.
HTTP/1.1 404 Not Found
Content-Type: application/problem+json
{"detail":"No report exists for that identifier."}
Expected result: 404 states that the origin did not find a current
representation for the target or is unwilling to disclose one. The JSON content
can add application detail but cannot redefine the HTTP status.
The request method changes what success content means
A 200 OK response to GET carries a representation of the target resource. A
200 response to POST carries the status or result of the action. A HEAD
response has no response content even though its fields describe the response a
corresponding GET would have produced.
Read the method, exact status, fields, and content together. “The request worked” is often too vague to explain what a successful response represents.
HTTP success is not the same as application success
A server can return 200 with an application error encoded in content, or 404
with a useful problem description. Conversely, a browser can receive a successful
HTTP response but prevent page JavaScript from reading it because of CORS.
Record both layers: the network response and the application’s interpretation. Do not replace one with the other in logs or diagnostics.
Unknown codes still have a class
HTTP permits extensions in the valid 100–599 range. A client that does not
recognize a code treats it like the x00 member of its class, except that it must
not cache an unrecognized response. Look up current registrations in IANA rather
than assuming a code is unused.
