A Look At HTTP Status Codes

Photo by visuals on Unsplash

A Look At HTTP Status Codes

·

8 min read

WHAT IS HTTP

Hypertext transfer protocol is a major principle regarding the exchange of data between web applications. It governs the exchange of various types of data, including text, images, videos, and other resources, between web servers and clients (such as web browsers).

HTTP STATUS CODES

Hypertext transfer protocol status codes are numbers or digits(usually three digits) a server generates in response to a browser’s request; When we request something from someone, we receive responses such as "yes, it is available," "no, I don't have it," or "I can't give it to you," among others. Similarly, when we request data from servers, HTTP status codes serve as responses that convey the status of the request, indicating whether it was successful or not, or if it encountered an error.
We have numerous status codes for various use cases or types of responses, which are categorized into five standard classes.

  1. Informational responses (1xx): These status codes are used to signify that the server has acknowledged the request and is currently processing it. These responses are considered informational, and temporary, and remain invisible to the client, examples are:

    1. 100 (Continue): This status code means that the server has received the initial request from the client and advises the client to proceed with the remainder of the request.

    2. 101 (Switching protocols): In response to an Upgrade header field request, this code signifies that the server intends to switch to the protocol specified in the request.

    3. 102 (Processing): This response informs the client that the server has received the request and is currently processing it. However, a complete response is not yet available.

    4. 103 (Early hints): When accompanied by the Link header, this status code allows the server to provide hints to the client about resources that may be needed in the future while it continues to prepare a response.

  2. Successful responses (2xx): These status codes indicate that the server has successfully received, understood, and processed the request, informing the client that their request was handled without encountering any issues.

    let's take a look at some of them;

    1. 200 (OK): This is the standard response for successful HTTP requests, It's the digital equivalent of receiving a gold star from the server, a reassuring nod that everything's in order.

    2. 201 (Created): This is usually the response after POST or PUT requests that the request was successful and a new resource has been created.

    3. 203 (Non-Authoritative Information): This indicates that the data provided did not originate from the primary server. Rather, it's a modified rendition obtained from an alternate or a third-party source.

    4. 204 (No Content): this means the request was processed successfully but the requested resource has no content available on it.

    5. 205 (Reset Content): In this scenario, the server has fulfilled the user's request, but it suggests that the user reset the document. This status code typically implies that the document has been modified and the user should clear any existing content before proceeding further. It's like the server saying, "Hey, I've done what you asked for, but now it's time to start fresh with a clean slate."

    6. 206 (Partial Content): This status code is utilized when the client specifies a Range header in the request, indicating a desire to retrieve only a portion of the requested resource.

    7. 207 (Multi-Status): This status code is used to provide information about the statuses of multiple resources, based on the number of sub-requests made. Sub-requests are additional requests made within an initial request. They are often used to retrieve or manipulate multiple resources in a single operation. For example, in a web application, a single HTTP request might trigger sub-requests to fetch data from multiple endpoints or perform various operations on the server. Sub-requests help streamline communication between clients and servers and can improve efficiency by reducing the number of round-trips required to accomplish a task.

  3. Redirection responses (3xx): The status codes in this group tell you that the content or data you're looking for has moved to a new resource, so your browser automatically takes you there instead.

    Known as the redirect status codes below are the lists of some of the codes in this category;

    1. 300 (Multiple Choice): This status code is used to let the client know that the requests sent have numerous responses and the client should pick one out of the several responses available.

    2. 301 (Moved Permanently): This redirect status code indicates the requested resource has permanently moved to a new URL. The browser displays the new URL.

    3. 302 (Found): This status code was known as "Moved Temporarily", this code indicates the requested resource has temporarily moved to a new URL.

    4. 303 (See Other): This status code is used by the server to redirect the client to the requested resource with a GET request at another URL.

    5. 303 (See Other): This code is used by the server to tell the client browser to go somewhere else to find what you're looking for. It sends you to a new place using a GET request.

    6. 304 (Not Modified): This means that nothing has changed since the last time you asked for it. So, you can keep using the version you already have saved in your browser's memory.

    7. 308 (Permanent Redirect): This status code means that the resource you're trying to find has moved to a new address for good. The main difference from 301 is that the client shouldn't change the HTTP request method.

  1. Client error responses (4xx): This category of HTTP status codes indicates the server can’t reach a page due to an error on the client side. some of these status codes used to let the client know of their errors are;

    1. 400 (Bad Request): This status code is sent by the server to let the client know a request can’t or won’t be processed due to an error from the client side. For example, if the client sends incomplete or incorrect information in the request, the server responds with this code.

    2. 401 (Unauthorized): this is used to let the user know they don’t have valid authentication credentials to get to the requested resource.

    3. 402 (Payment Required): Reserved for future use; it was initially intended for digital payment systems. It’s very rarely used, and no standard convention regulates it.

    4. 403 (Forbidden): This means the client isn't allowed to access the content. It's like a locked door that requires a password to enter. Unlike the 401 code, the server does know who the client is.

    5. 404 (Not Found): this means the server couldn't find what the user is looking for, and it hasn't told the browser where else to look.do you know seeing a 404 error can hurt your website's search engine ranking?

    6. 405 (Method Not Allowed): This means the server understands the client is trying to get content from a resource, this code is usually sent when a user is using a HTTP request that is not supported on the location of the resource.

    7. 409 (Conflict): This code indicates that the server cannot carry out the client's request because there is a conflict with the resource. For instance, if a client tries to create a user that already exists on the resource, the server will return this status code.

    8. 415 (Unsupported Media Type): This code means the server can't understand the type of data the client is sending. It's like trying to play a video file on a device that doesn't support that format.

    9. 422 (Unprocessable Entity): This status code indicates that the server received the request from the client, but it can't understand or process it due to errors in the content or similar issues. It's like trying to fill out a form with missing or incorrect information.

  2. Server error responses (5xx): This group of status codes covers errors that happen on the server's side. They're like when the chef messes up your order in the kitchen.

    For example, if the chef accidentally burns your jollof, that's a server error. These errors can be bad for your website's SEO because search engines might get annoyed and stop visiting if they keep encountering problems.

    let's dive into some of them quickly;

    1. 500 (Internal Server Error): This means something went wrong on the server's side, but it's not your fault hence the analogy about the chef and burnt jollof above.

    2. 501 (Not Implemented): This means the server does not know how to handle the request by the client. It's like trying to speak a language the chef doesn't understand; like ordering a food that is not on the menu.

    3. 502 (Bad Gateway): This code is usually returned by the server when the server acts like a middleman, passing along the client request to another server, but it gets a bad response from that server. It's like trying to deliver a package, but the delivery person finds the address is wrong.

    4. 504 (Service Unavailable): The server is unable to process the request. This often occurs when a server is overloaded or down for maintenance.

    5. 504 (Gateway Timeout): This means the server was trying to pass the client request to another server, but it took too long to get a response. It's like waiting for a friend to open the door but they're taking forever to answer.

    6. 505 (HTTP Version Not Supported): The server doesn’t support the HTTP version in the request.


In the realm of software development, effective communication is paramount. HTTP status codes play a crucial role in facilitating this communication, serving as a universal language between servers and clients. These codes provide clear and concise feedback, guiding users and developers alike through the intricacies of web interactions.

While we've touched upon the significance of HTTP status codes, it's important to note that there are numerous codes beyond those discussed here. For a comprehensive understanding, explore the full range of HTTP status codes in a fun way.

Organizations often enhance this communication by employing custom status codes, tailoring responses to meet specific needs, or conveying unique messages. For instance, generating JSON formats with messages like "success" alongside custom codes, such as "00," is a common practice. This not only streamlines user experiences but also aids developers in troubleshooting and debugging processes.

In essence, HTTP status codes are fundamental concepts in web development and software engineering as a whole. They foster transparent and efficient communication, enhancing both user satisfaction and developer productivity.