Demystifying HTTP 2: Dummy's Guide to Understanding the Web's Backbone

Anaele JoshuaAnaele Joshua
4 min read

Hi there, good to have you in my corner again. If this is your first time entering my corner, I am delighted to have you here.

In this post, I will be delving deeper into the HTTP response format, HTTP status codes, and their meaning as I promised in my previous post. This post is a continuation of my previous post, I will recommend you check it out before you continue with this, however, you can choose to continue.

HTTP Response

When a server receives a request from a client, it processes the request and sends back an appropriate Response to the client. This response is composed mainly of a status line, a header(optional), and a body.

Status line: This line shows the client if the request was successful or an error occurred.

HTTP/1.1 200 OK

The line begins with the HTTP protocol version, followed by the status code and a reason phrase. The reason phrase represents the status code in a text form. In the example above HTTP/1.1 is the version, 200 is the status code and OK is the reason phrase.

HTTP STATUS CODES

The first digit of an HTTP status code shows the response category. 1xx for Information, 2xx for Successful, 3xx for Redirection, 4xx for Client Error, and 5xx for Server Errors.

1xx (Informational status codes):

The information status code ranges from 100 to 199. Below are some of the most common information status codes.

Status CodeReason PhraseDescription
100ContinueThe server received the request headers and should continue to send the request body
101switching protocolThe client has asked the server to switch protocol, and the server has agreed to do so

The 1xx status codes are regarded as transitional codes, they are not the final status code.

2xx (Success status codes)

The information status code ranges from 200 to 299. Below are some of the most common information status codes.

Status CodeReason PhraseDescription
200OKThis is the standard response sent by the server to show it successfully processed the request
201CreatedThe server has processed the request, and the resource has been created
202AcceptedThe server accepted the request for processing, but the request has not yet been processed
204No contentThe server successfully processed the request but is not returning any content

200 ok is the most common of the 2xx status codes.

3xx Redirection

The information status code ranges from 300 to 399. Below are some of the most common information status codes.

Status CodeReason PhraseDescription
301Moved PermanentlyThis request and all future requests should be sent to the returned location.
302FoundThis request should be sent to the returned location.

4xx Client Error

These are responses because of errors from the client. They range from 400 to 499. Below are some of the most common responses of the 400 series.

Status codeReason phraseDescription
400Bad RequestThe server cannot process the request due to a client error, e.g., invalid request or transmitted data is too large, deceptive request routing.
401UnauthorizedThe client is unauthorized and needs to authenticate itself to get the response requested.
403ForbiddenThe request is valid, but the server is refusing to process it because the client does not have the required permission to access the requested resource.
404Not FoundThe server did not find the requested resource.
405Method Not AllowedThe web server does not support the HTTP method used on the target resource.

500 Server Error:

Status CodeReason PhraseDescription
500Internal Server ErrorA generic error status code given, when an unexpected error or condition occurs while processing the request.
502Bad GatewayThe web server received an invalid response from the Application Server.
503Service UnavailableThe web server cannot process the request. Common causes for this might be server overloading or server is down for maintenance.

HTTP Response Header

following the HTTP status line is a header (optional). The response header similar to the request header can contain a variety of information such as date, server type, content length, and type.

Date: Sunday, 15 Oct 2023 15:00:00 GMT+2

Server: Apache/2.2.14 (Linux)

Content-Length: 84

Content-Type: text/html

  • The Date header specifies the date time the response was generated.

  • The Server describes the web server software used to generate the response.

  • The Content-length specifies the length of the content.

  • The Content-type specifies header describes the media type of the resource returned. e.g. HTML document, image, video.

HTTP Response Body

Following the response header is the response body. The response body contains the resource that was requested.

10
Subscribe to my newsletter

Read articles from Anaele Joshua directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Anaele Joshua
Anaele Joshua

I am a software engineer. I Love to learn. The more I learn, The more I see the limitations of my understanding, so I am always learning. I also love to teach and share knowledge, I found that to be a secret recipe to understanding better.