Have you ever tried surfing the web for something and been slapped with an error 404: Oops, Page Not Found or an error 500: Internal Server Error message? And you keep trying to reload that site, but it keeps giving you the same response?
For a user, this can be a very frustrating experience. However, these are HTTP status codes that do more than just communicate error responses. These codes can also indicate a successful transmission or a redirect to a different web address.
I know you must be wondering, "What is HTTP and status codes?". In this blog post, we will go over HTTP and its response status codes. Consider this a small cheat sheet to use whenever you come across one.
So, let's get to it!🤓
What is HTTP?
HTTP stands for Hypertext Transfer Protocol. HTTP is the World Wide Web's primary operational protocol. It allows your web browser to communicate with a web server, which hosts a website. HTTP is a protocol that uses a request-response model. A web browser or client sends an HTTP request to a server, and the server responds with an HTTP response.
As a result, whenever you visit a website and click on a link, your browser sends a request to the server in order to retrieve the data for the web address you clicked on or entered. The server processes the request and returns the necessary data.
Every time you visit a website, your browser receives an HTTP Status code, but it is not always visible to you unless there's an error.
What is an HTTP Status Code?
When you try to access a webpage, your browser sends a request to the web server that hosts the webpage, and the server responds with a code that indicates the status of the request.
The web server can return a set number of responses based on whether the transmission was successful or not. If it fails, the server sends an Error message with an HTTP Status Code so you can see what went wrong.
Categories of HTTP Status Codes
The first digit of an HTTP status code indicates the category of the response, and there are five standard categories of status codes. They are as follows:
1XX - Informational responses
2XX - Successful responses
3XX - Redirection responses
4XX - Client error responses
5XX - Server error responses
Let's go over each category and talk about the most common status codes.
1XX - Informational Responses
An informational response means that your web browser has sent a request to the server and is awaiting a response. It is usually issued on a provisional basis while the request is being processed.
100 - Continue: This is an interim response indicating that the first part of the request was received and that the client should proceed.
101 - Switching Protocols: Your browser has requested that the server switch protocols, and the server has agreed.
102 - Processing: This status code indicates that the server received and is processing the request, but no response is yet available. This prevents the client from timing out and concluding that the request was unsuccessful.
103 - Early Hints: The server is sending some “early hints” to your browser to preload certain resources while the server provides a final response.
2XX - Successful Responses
These status codes indicate that the action requested by the client (your web browser) was received, understood, and accepted.
200 - Ok: This is the standard response for successful HTTP requests. This is the code that is delivered when a web page or resource acts exactly the way it’s supposed to.
201 - Created: Your browser request has been fulfilled, and as a result, a new resource has been created.
202 - Accepted: This code indicates that the request has been accepted for processing, but the processing has not been completed.
204 - No Content: This code means that the server has successfully processed the request but has no content to return.
3XX - Redirection Responses
This class of status code indicates the client must take additional action to complete the request.
301 - Moved Permanently: The server redirects your browser to a different URL because the desired resource has been permanently moved to a new location.
305 - Use Proxy: The server requires a proxy in order to return the requested resource, and the address is provided in the response.
307 - Temporary Redirect: This status code indicates that the requested response has been temporarily moved to another URL, however, future requests should still use the original URL.
4XX - Client Error Responses
These status codes are intended for situations where the error appears to have been caused by the client.
400 - Bad Request: The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
401 - Unauthorized: This particular response is similar to the 403: Forbidden response. It indicates that the client lacks valid authentication credentials to access the requested resource.
403 - Forbidden: The request contained valid data and was understood by the server, but the server has refused to take action. This may be due to the client not having the necessary permissions for the resource.
404 - Not Found: This response code is probably the most well known due to its frequent occurrence on the web. This status code indicates that the server was unable to locate the requested resources or that they don't exist but may exist in the future.
405 - Method Not Allowed: This status code indicates that the server is aware of the requested method but that the target resource does not support it.
414 - URI Too Long: The URI (Uniform Resource Identifier) requested by the client was too long for the server to process.
429 - Too Many Requests: This code indicates that the client has sent too many requests in a short period of time. Intended for use with rate-limiting schemes.
5XX - Server Error Responses
These status codes indicate that a request was not successfully processed by the server.
500 - Internal Server Error: This is a generic error message returned by the server when an unexpected condition prevents it from completing a request.
501 - Not Implemented: Either the server does not recognize the request method or is unable to fulfill the request.
502 - Bad Gateway: The server was acting as a gateway or proxy and received an invalid response from the upstream server. This is usually because the server was unsure how to handle the given request.
503 - Service Unavailable: The server is temporarily unable to handle the request due to maintenance downtime, overloaded servers, or other factors.
This is not an exhaustive list of all HTTP Status codes; however, it includes the most common ones because some of the codes are uncommon.
So, I hope you found this article useful, and if you've made it this far, please like it and share your valuable feedback. I'd appreciate all the feedback I can get. I would love to connect with you on Twitter | LinkedIn.
Resources:
Until next time, Take care!!