What is HTTP protocol?
Table of contents
In this blog, we will understand what is HTTP protocol and its basic features with examples.
Okay, so it's a protocol, so what does it mean?
A protocol means a set of rules and regulations or guidelines while communicating or executing a task.
Okay, but why do we need protocol in accessing websites from the internet
So, let's understand this,
What we do with accessing the internet is we request data as a client and the server responds with data, so exchanging data or information, that is communication is being taken place here.
This communication between server and client must be guided by certain rules, and have certain standards or structure for requests and responses, therefore named protocol.
Since this helps in exchanging data on the internet, these are also called network protocols.
HTTP protocol role
There are many protocols to perform communication (at the application layer). For example, FTP, SMTP, and POP.
HTTP is for fetching or accessing web pages from the internet by making requests and obtaining responses.
HTTP features
Let's understand the features with an example,
In the olden days, people used to write letters to communicate among themselves. While writing letters, they mention the
To represent the sender's address and
From the address representing the recipient's address and
the body contains the message.
Once the letter is dropped at the post office, the sender doesn't wait till the response arrives from the recipient. The sender carries on with other tasks.
When the recipient receives the letter, the message is read and an appropriate reply letter is written by the recipient.
- The reply letter also has the To and From address and body as a response.
Similarly, the client and server communicate through HTTP protocol in the same way.
The client or the browser is the sender here, makes a request (letter in above context) to the server asking for this resource https://eloquentjavascript.net/18_http.html
A simple get request header looks like this.
GET /18_http.html HTTP/1.1
Host: [eloquentjavascript.net](<http://eloquentjavascript.net/>)
<-- server -->
User-Agent: Chrome/89.0.4389.128 <-- client -->
The To and From addresses are given in the Request Header.
To address is Host (the server)
From address is the User-Agent (the client)
After that, it makes itself idle and doesn't wait for the server's response.
It loses the connection with server after sending request, hence it is connectionless.
It is the server's https://eloquentjavascript.net/ responsibility to give the resource asked.
The server (recipient in our case) on receiving the request searches in its drive for the resource and gives the response.
Any type of media content such as json, xml, images and html pages etc..., can be sent in the response as long as client or the browser can present it. Hence it is media-independent.
The response also has a response-header where it has
the To address pointing to the client's address
and From address pointing the server's address.
similar to the letter recipient writing reply letter to the sender.
After sending response, the server disconnects from the client.
So, the whole analogy is to make understand is that it does not require the server to retain session information or status about each communicating partner for the duration of multiple requests.
It is stateless since the server or client doesn't remember each other after disconnected.
Each time you want a resource from the server, you(client) need to make fresh requests to the server with From and To address in the request header.
If it is a stateful protocol, then the server and client maintain the information about each throughout the session. An example is communicating through telephone.
Conclusion
Understood what's a protocol and why protocols are used while accessing internet.
HTTP protocol.
Basic features of the HTTP protocol, that is media-independency, connectionless and stateless are understood.
Subscribe to my newsletter
Read articles from Manasa Mandalreddy directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Manasa Mandalreddy
Manasa Mandalreddy
I record my learnings and experiences as blogs in web development.