DEV Community

Cover image for HTTP Explained Like You are 5
Mufida Zuhra
Mufida Zuhra

Posted on

HTTP Explained Like You are 5

Most of us probably know that HTTP stands for

Hypertext Transfer Protocol

But what is it exactly?

Let's break down http word by word. It is a hypertext, transfer, protocol.

It is a protocol to transfer a hypertext.

Ok but what is a hypertext?

The main difference between a hypertext and a normal text lies in the word 'hyper'

Which means 'linked' texts.

A hypertext links texts to another texts. It creates a series of interconnected texts.

So if you find a clickable link in a text, and that link lead you to another text, that is essentially what a hypertext is. Which is pretty much what web pages are all about!.

When you click a link in a webpage, it will lead you to another page, right?

So hypertext is just a normal web pages!. That is all there is to it!.

And HTTP is the protocol that rules how hypertexts a.k.a web pages are
transferred from the server to the client.

If you're not sure what client-server is all about, here's a refresher:

When you visit a website, the client is the device you use to visit that website. So this could be your phone, your laptop, or your computer.

While the server is the machine that's hosting that website. Normally located miles away on the other side of the world.

When you open google chrome to visit youtube, chrome here is the client and youtube is the server.

You need to know that pretty much every interaction on the web happen between a client and a server. And client-server interaction is all about

request and response

If chrome wants a youtube homepage, chrome will send a request to the youtube server and youtube will send a response by giving chrome the youtube homepage. This is what request and response is all about. A request comes from the client, and the server replies with a response.

And HTTP rules this request and response process.

If we humans interact in real life, we also have 'rules' to communicate to one another, right?. Where we perhaps begin with saying hi first, then show good body gestures, choose polite words, and maintain eye contact.

It's the same thing with the client and server interaction on the internet.

HTTP is the rule that governs this interaction.

For a better understanding, think of http as the 'language' spoken by the client and the server. It is the 'language' they speak to send request and receive response.

This is the essence of HTTP.

Client and server.

Request and response.

That being said, everything about HTTP revolves around details and information about the request and response.

Information about the request and response process is found in what's called the

HTTP message

Think about this like the 'grammar structure' of HTTP.

If you intercept a client and server 'conversation', you'll find that the 'grammar' they speak or the HTTP message is consist of two main parts:

the HTTP header
the HTTP body

The HTTP body contain the actual data that is being interchanged between a client and a server.

But you need to know that information and details about the request and response are found inside the HTTP headers.

And the HTTP header for request is different to the http header for response. The structure looks similar but the information they carry is different.

Request is about the client asking something from the server, right? so the request http header contain information about what kind of request that the client want from the server.

Think about it, what kind of action can you do on a website?. You can view pages, you can upload photos, texts, videos, you can delete files, you can click a button, etc.

Your action is defined by what's called the

HTTP methods

And it is typically a get or a post method. If you're not sure what they mean, when you're visiting a website, your action is either passive or active, right?.

Passive is when you're viewing things. Like viewing a page, or watching a youtube video, where the server is giving you something. where you retrieve or get something from the server.
This is what a get method is.

Active is when you upload a comment, or upload an insta story, or tap a like button. where you post or submit something to the server.
This is what a post method is.

Of course there are other methods beside get and post. we also have put, patch, delete, etc. But get and post are the most common request methods.

So HTTP request header must contain the http methods to define the client action. This is to tell the server what to do with the client request.

On the other hand, the http response header must contain what's known as

the http status codes

What is a status code?

When you type 'www.linkedin.com', your browser is sending a get request to the linkedin server, asking linkedin to give you the homepage. When linkedin responds by giving you the homepage, it contains a

HTTP status code of 200

Which means successful response.

But when you are requesting for a page that does not exist, like when you mistyped a link, linkedin will check its server, see that the server has no file for this link, so instead, linkedin will send an error message.

like a 404 page.

404 means the server you send a request to does not have the page or the file that you requested for.

This 404 error message and the 200 success message are

HTTP status codes

The status code helps the client know what kind of 'reaction' the server is giving upon its request. And of course it's not limited to 200 and 404.

There are other numbers like 403, 504, 100, etc, each represents different 'reaction'.

So to recap, HTTP is the protocol that govern the request and response process between a client and a server. When a client is communicating with a server, their request and response details are defined inside
the http headers. The http header for client is different to the http header for server.

Client is about asking request and server is about giving response. To understand the client request, the server needs to know the client action, which is defined by the HTTP methods.

To know whether the server has completed the request, the client needs to know the server response. which is defined by the http status codes.

they are defined in the startline of an HTTP header message.

HTTP request header contains the HTTP methods

the HTTP response header contains the HTTP status codes.

HTTP message

Top comments (0)