Skip to content

The Anatomy of a HTTP Request

by David Yates

I’m a software engineer by trade, and my job has mainly seen me working with web technologies. I’m going through a bit of a “back to basics” perios and thought I might revisit some of these 101 topics while I do some work on my blog (I needed an excuse to try out the mermaid rendering engine for diagrams 🙂).

Whenever I teach someone about web development, I always start with the basics. I think it’s important to understand the fundamentals of how the web works before you start building things on top of it. I’m going to start with the basics of HTTP. So let’s get started.

What is HTTP?

All communication systems need a protocol. A protocol is a set of rules that govern how two or more entities communicate. When you call someone, you establish a connection with them via a protocol. You dial their number, they answer, you say hello, they say hello back, you ask how they are, they ask how you are, etc. This is a protocol. As the internet has grown, so has the need for protocols. The internet is a network of networks, and it needs a protocol to govern how these networks communicate with each other. This is where HTTP comes in.

HTTP stands for HyperText Transfer Protocol. It is a protocol that allows for the transfer of data between a client and a server. It is the foundation of the web and is used to transfer data between a client (usually a web browser) and a server (usually a web server). It is a stateless protocol, which means that each request is independent of the previous request. This means that each request can be handled independently of the previous request. This is important because it allows for the web to scale to millions of users.

HTTPS is a secure version of HTTP. It uses TLS (Transport Layer Security) to encrypt the data being transferred between the client and the server. This is important because it prevents anyone from eavesdropping on the data being transferred. It also prevents anyone from tampering with the data being transferred. For this post though we will be focusing just on HTTP.

What is a HTTP Request?

When you make a request to a web server, usually from a web browser, you are sending a HTTP request. The server then responds with a HTTP response. The HTTP request contains information about the request, such as the URL of the resource being requested, the method used to make the request, and any headers that are sent with the request. The HTTP response contains information about the response, such as the status code, the content type, and any headers that are sent with the response.

A HTTP Request when you log it out looks like this:

GET /index.html HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Connection: keep-alive

… and so on. You can garner a lot of information from a HTTP request. The most important thing to know is that it is a request for a resource. The resource can be anything from a web page to a file to a database record. The request is made up of a few different parts:

Loading graph...

What is a HTTP Response?

After receiving a HTTP request, the server sends back a HTTP response. The response contains information about the result of the request, such as the status code, the content type, and any headers that are sent with the response.

A typical HTTP Response might look like this:

HTTP/1.1 200 OK
Date: Sat, 10 Sep 2023 13:14:33 GMT
Server: Apache/2.4.6 (CentOS)
Content-Type: text/html; charset=UTF-8
Content-Length: 138
X-Powered-By: PHP/7.0.25
X-Frame-Options: SAMEORIGIN

The response is made up of a few different parts:

Loading graph...

and thats a wrap! Understanding HTTP requests and responses is a fundamental part of web development. I hope this post has helped you understand the basics of HTTP. If you have any questions, please feel free to leave a comment below. Thanks for reading!

All Posts