HTTP status codes are a fundamental part of the modern Internet. Whether you are consuming APIs or requesting remote resources, you will be making use of HTTP status codes.
As a developer these status codes can tell you a lot and help you to identify issues in your application, and also to be able to handle better error messages for your users.
You may already be aware of some of these, probably the most famous is the 404 Not Found. But did you know that these codes have very precise categories?
HTTP Status Code Categories
1xx - Informational Response
Any status code which begins with a 1 is an informational response and are typically issued while the request continues processing.
Some informational response codes include:
- 100 Continue indicates that everything so far is OK and that the client should continue with the request, or ignore it if it has already finished.
- 101 Switching Protocols indicates a protocol to which the server switches. With a 101 response the protocol to which the server switches is specified in the Upgrade header which is also sent from the client. One example of a 101 Switching Protocols status code would be when you make a connection to a WebSocket server.
2xx - Successful
Any status code which begins with a 2 is an indication that the requested action from the client was received by the server, it was understood and accepted.
Generally the most common successful status code is a 200 OK. A 200 is the standard response for successful HTTP requests.
Some successful HTTP status codes which you may see include:
- 200 OK indicates that the request was received and understood by the server and accepted.
- 202 Accepted indicates that the request made has been accepted for processing, but this processing has not yet completed.
- 204 No Content indicates that the server was able to successfully process the request, but there is no content to return to the client.
3xx - Redirection
When a status code begins with a 3 this means that it is redirection. This indicates that the client must take additional action in order to complete the request.
Some of the most common HTTP redirection status codes include:
- 301 Moved Permanently indicates that the initial and all future requested should be directed to a given URI.
- 302 Found (Moved Temporarily) indicates that the client should look at a URL. The difference between this and 301 is 302 suggests that the requested resource will only temporarily be available from the new URL, but 301 suggests it is permanent.
If you are involved in SEO then you will typically be making use of HTTP 301 and 302 status codes on your servers quite often.
4xx - Client Error
Any HTTP status code which begins with a 4 is an indicator that an error has been caused by the client.
Some of the most common HTTP client error status codes include:
- 401 Unauthorized indicates that authentication is required but has failed or has not yet been provided.
- 403 Forbidden indicates that the request was valid and was understood but the server is refusing action. This is similar to a 401 Unauthorized, however a 403 might be where a user has authenticated but is attempting to request a resource which they don't have permission to access, whereas a 401 is where the user hasn't authenticated at all.
- 404 Not Found is quite possibly the most famous HTTP status code of them all and it indicates that the requested resource could not be found on the server.
- 418 I'm a teapot is a status code which is returned by teapots which have been requested to brew coffee.
5xx - Server Error
When a HTTP status code begins with a 5 this indicates that there was a problem with the server and so it was unable to fulfil the request.
Some server error HTTP status codes which you may see include:
- 500 Internal Server Error is a generic error message which is often returned when the server is not configured to handle the response.
- 503 Service Unavailable is when the server cannot handle the request, often because it is overloaded or is down for maintenance. A 503 status is typically a temporary state.
How can I view HTTP status codes?
As status codes are a fundamental part of browsing any website, the simplest way to view them would be to open up the Network Monitor on your browser whilst viewing the website. This will show you the state of the requested resources as you load different parts of a website.
Firefox
To view the Network Monitor on Firefox press Ctrl + Shift + E. This will open a window on your page with the "Network" tab highlighted. Then if you refresh your page you will see all of the resources which are requested with that page.
Chrome
To view the Network Monitor on Chrome press Ctrl + Shift + J. This will open the console window. Then select the "Network" tab. Then refresh your page and you will see all of the resources which are requested with that page.
Top comments (1)
I've just learned they retired 418 😢
rfc-editor.org/rfc/rfc9110#name-41...