DEV Community

Cover image for What is HTTP? (... for newbies)
varbSan
varbSan

Posted on

What is HTTP? (... for newbies)

Intro

HTTP stands for Hypertext Transfer Protocol. It is the protocol allowing "clients" and "servers" to exchange information on the web at the Application Layer[^1].
For example, your computer is the client asking for the data of this very web page to a server, another computer over the internet. For the server to understand the client and vice versa they need to follow the same "standards": the HTTP protocol.

Interactions between server and client can take 2 forms: an HTTP request or an HTTP response. These requests and responses are carried and can be altered by proxies. The protocol is improving over time, new versions have been released since its birth in 1991.

Let's dive deeper into this!

What is an HTTP request?

An HTTP request is how the client can "talk" to the server.
This request contains a request line, a header, and optionally a body. You specify the method in the request line so the server knows what type of action is excepted. There are 8 methods but the main 5 are:

  • "GET" to retrieve data from the server
  • "POST" to submit data from the server
  • "DELETE" to erase data from the server
  • "PUT" to completely update data from the server.
  • "PATCH" to partially update data from the server.

The request header contains meta-information about the request and the client itself, like the browser and the OS used.

E.g. after you complete a sign-up form with your username and password, you click on submit. Clicking on the submit button triggers an HTTP request. The first line of the request informs the server it's a post request, the body of the request contains the username and the password so the server can process this information.

In addition to the method, the request line contains the url targeted and the HTTP protocol version the client wants to use using.

What is an HTTP response ?

An HTTP response is how the server can talk back to the client after an HTTP request.
This HTTP response contains a status code, a header and an optional body.

The status code gives information about how the request was processed by the server

A status code in between 100 and 199 provides information
A status code in between 200 and 299 states the request was successful
A status code in between 300 and 399 informs there is a redirection
A status code in between 400 and 499 informs of an error coming from the client
A status code in between 500 and 599 informs of an error coming from the server

The response header contains meta-information about the response and the server itself.
The body contains the most important information: usually the HTML content for the webpage the client asked for.

What are proxies?

Proxies are computers in-between the client and the server. They carry the HTTP request and response. They can be routers, or modems or more. They can act as caches, gateways etc.
The point is the HTTP message get handled by many computers between the client and the server. We already know many computers handle the data travelling at the Transport Layer[^2], but proxies refer to computers handling the data at the Application Layer. They handle the HTTP message itself.
E.g. when an image get cached for you. A proxy does the caching in between you and the server.

How new versions improved HTTP?

In 1991, HTTP 0.9 was the first HTTP protocol. It just had the GET method, and no header. Only HTML was supported in the response body.

In 1996, HTTP 1.0 was released. The POST method was added to the options for the request line. Meaning, you could now, not only retrieve, but also submit data to a server. The request and response were given a header. Status codes were introduced. And finally, the response body could include images and videos besides HTML text. This made "HTTP" a misnomer. HMTP (for Hyper Media Transfer Protocol) would have been more accurate but we kept the HTTP acronym for some reason.
Even though HTTP 1.0 added many features some issues remained. The main one was related to the Transport Layer. Long story short, the connection between server and client was closed after each request. In consequence, Three-way Handshake[^3] had to be repeated for each request, causing performance issues.
E.g., loading a page with multiple images was unecessary slow because the client and the server needed to have a back and forth in 3 steps to establish the connection.

In 1999, HTTP 1.1 was released. The DELETE method was added. And performance was improved by the addition of persistent connections between server and client by default. Pipelining was also added, enabling the client to send many request to a server without waiting to receive the first responses.

In 2015, HTTP 2.0 made the protocol improve again in performance, security and more.

In Short

HTTP is the protocol running the Web. It allows clients and servers to "talk" to each other through requests and responses.

These interactions are handled by intermediates called proxies.

Although the base stays the same, HTTP has had several versions of itself since being born in 1991. Each version improved the previous one by adding features, increasing performance, and reinforcing security.

References

Footnotes
[1]: See Application Layer
[2]: See Transmission Control Protocol (TCP)
[3]: See Three-way Handshake, which is a back and forth between client and server in 3 steps to establish TCP connection.

Sources

Top comments (1)

Collapse
 
daitodev profile image
Dave Notori

Amazing post, I now have a clearer understanding of the HTTP protocol after reading this!