Today we are going to learn about the world’s most used internet protocol i.e. HTTP Protocol, which stands for HyperText Transfer Protocol. When we are saying HTTP means we need to talk about how a web works. At least have a general idea so we come to know how HTTP works.
The HTTP Protocol:
It stands for HyperText Transfer Protocol. It is an application layer protocol that allows web-based applications to communicate and exchange data. You can think of an HTTP as a messenger of the Web. It is a TCP/IP based protocol. It is used to deliver contents like – images, videos, audios, Documents etc. and if the two computers want to communicate and exchange data then the client and server usually in form of a request-response cycle they both must speak the HTTP communication Protocol. The client is usually a computer that makes a request and the server is the one that serves by responding to the request.
3 important things about HTTP Protocol:
1. HTTP is a connectionless protocol: – After making the request the client disconnects from the server, then when the response is ready the server re-establishes the connection again and deliver the response. So this is called a connectionless protocol.
2. The HTTP can deliver any sort of data as long as the two computers are able to read it.
3. The HTTP is stateless:- The client and server know about each other just during the current request. If it closes, and the two computers want to connect again then they need to provide information to each other anew and the connection is handled as the very first one.
Let’s discuss Why to choose HTTP over other Protocols?
HTTP was designed mainly to fetch HTML documents and sends it to the client. It was designed in an exquisite way. It was being continually evolved and features were being added to it. It became the most convenient way to quickly and reliably move data on the web.
Let’s see How the Web works and how HTTP makes that Possible?
First, let’s see how the Request-Response cycle works: –
Consider we have a client on one side and the web server on the other side. Suppose A user or Client wants to see a website for ex. www.hostdens.com. The client types the URL of the website in the browser but first, they need to be physically connected that is the computer of the client and the server. It is done by the internet. Using the TCP/IP protocol internet establishes a connection between the client and a server using cable media or a wireless media and at the same time, it does all the necessary work to prepare the environment for the two computers to talk using the HTTP protocol. When the connection establishes the client sends a request which is called as HTTP message and because the HTTP is connectionless protocol the client disconnects from the server and waits for the server response. The server on the other side process the request, prepares the response, establishes the connection again and sends back to the client and then the two computers completely disconnects. Now, because the HTTP is a protocol it is defined by a set of precise rules.
Now Let’s look at the format of the HTTP message :
A typical HTTP message is formed with 3 parts: – Start line, Header, and Body.
They all contain plain text-based information unless the body contains binary data. In general, they are plain text and easy to read.
The information in the 3 sections vary depending on the HTTP message, whether it is a request or a response. A request HTTP message differs from Response HTTP message. We are going to take a look at this.
The format of an HTTP Request :
Here we have a start line which contains method, URI, HTTP Version.
Headers contain- Host, Accept and Accept-language and there is nobody section. It is not needed.
The Method – Is a command that tells the server what to do . for ex. GET, POST. In our case, it is GET – as the client is requesting for a data.
URI – is a set of readable characters and a way to locate the response.
Host – The address of a server to which we are sending the request i.e. www.hostdens.com
Accept-Language – Specify the language.
Accept – It is a MIME type or a type of file we want.
The format of a Response HTTP message –
Star Line – Here the URI and method are not present. Because those are required for the Request.
Here we have HTTP Version and Status Code – Which is a code that tells the client if the request is succeeded or failed.
Header – Contains Name
Response Body – contains File requested.
This is how HTTP message looks like. It can be complicated.
Let’s Sum up :
- HTTP is a TCP/IP application layer protocol that allows web-based Application to communicate and exchange data.
- The Computers that communicate via the HTTP must speak the HTTP Protocol.
- The HTTP is stateless, connectionless and can deliver any data.
- We use the HTTP Protocol because it is a convenient way to quickly and reliably move data on the web.
- The request-response cycle works on the web via HTTP message.
- An HTTP message contains 3 parts – Section, the Start line, the header and the Body.