Status codes

Even when an application has constructed a valid HTTP request object, and submits that request to a valid path on an active host, it's not uncommon for the server to fail to properly respond. For this reason, HTTP designates, as part of a response object, a status code to communicate the ability of the server to properly service the request. HTTP status codes are, by convention, 3-digit numeric codes returned as part of every response. The first digit indicates the general nature of the response, and the second and third digits will tell you the exact issue encountered. In this way, we can say that status codes are categorized by their first digits.

When you're writing software that responds to HTTP requests, it's important to send accurate status codes in response to different errors. HTTP is a standard that must be adhered to by developers in order to remain useful.

There are only five valid values for the first digit of an HTTP status code, and thus, five categories of responses; they are as follows:

  • 1XX: Informational status code. This indicates that the request was in fact received, and the processing of that request is continuing.
  • 2XX: Success status code. This indicates that the request was successfully received and responded to.
  • 3XX: Redirection. This indicates that the requesting host must send their request to a new location for it to be successfully processed.
  • 4XX: Client Error. An error that is produced by the actions of the client, such as sending a malformed request or attempting to access resources from the wrong location.
  • 5XX: Server Error. There was a fault on the server preventing it from being able to fulfill a request. The client submitted the request correctly, but the server failed to satisfy it.

Status codes are returned by servers for every HTTP request made against the server, and so can be very useful for building resiliency into your client software.