Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction:
2.
What is HTTP?
3.
Working of HTTP
4.
Components of HTTP-based systems:
4.1.
Clients:
4.2.
Server:
4.3.
Proxies:
5.
HTTP Request:
6.
HTTP Response:
7.
HTTP Flow:
8.
Features of HTTP:
9.
Advantages of HTTP:
10.
Disadvantages of HTTP:
11.
Functions of HTTP:
12.
Frequently Asked Questions
12.1.
What are Persistent Connections?
12.2.
What is the difference between HTTP and FTP?
12.3.
What is the difference between TCP and HTTP?
12.4.
Is HTTP the web?
12.5.
What is the difference between HTTP and HTTPS?
13.
Conclusion
Last Updated: Mar 27, 2024
Medium

What is HTTP?

Author Jessica Mishra
6 upvotes

Introduction:

HTTP stands for Hypertext Transfer Protocol. It is the foundation of the World Wide Web and is used to deliver the data like HTML(HyperText Markup Language)  files, image files, query results, etc., on the WWW.  It is a protocol designed to transfer information between networked devices. 

It is an application layer protocol, defining how clients and servers (who are running the system on different ends) pass messages to each other. 

http coding

Now, this transfer of information has a flow. In that flow, the client requests the server, sending a response message in return. These messages are sent using a web browser. 

What is HTTP?

HTTP (Hypertext Transfer Protocol) is a file-transferring protocol used for communication between web clients (an application that runs on a user’s device that can request information from a web server) and web servers (an application that runs on a server computer and answers the requests made by web clients). The WWW (World Wide Web) used this protocol to transfer information over the Internet.

Working of HTTP

  • Request: You request a web page by typing a URL or clicking a link in your browser.
  • Sending the Request: Your request travels over the Internet to a web server using HTTP.
  • Server Processing: The web server processes your request, finds the requested content, and generates an HTTP response.
  • Sending the Response: The response travels back to your browser.
  • Rendering: Your browser interprets the response and displays the web page with text, images, and interactivity.
  • Optional Additional Requests: Your browser may send additional requests if the page has more content, e.g., images.
  • Interaction: You interact with the web page, triggering more requests as needed.
  • Continuous Interaction: This process repeats as you navigate and interact with websites.

Components of HTTP-based systems:

There are many entities between clients and servers. These are known as proxies which act as a gateway and perform functions. Let us look at different components of HTTP systems:

Clients:

The user agent or the client is the system that acts on behalf of the user. It requests the browser, and the browser initiates the request to the server. The browser sends a request to fetch the HTML document representing the page's structure for displaying the web page. After parsing this file, it makes additional requests for the layout part of the website, i.e., CSS, to show the page and sub-resources like images and videos. After combining these documents, the web page is presented to the user. 

If the user clicks on a link in the document or wants to access another webpage, the browser will again make HTTP requests to accomplish that.

Server:

At the opposite end of this channel is the server. It contains all the information that the client needs. It supplies all this information according to the requests made by the user. We consider the server as a single machine during representation, but that is not necessary for reality. The server can be a collection of machines or a collection of software sharing the load. 

To better understand the server and the client, refer to the Introduction to Servers and Clients blog.

Proxies:

Several machines and computers between the client and the server are known as proxies. Some are transparent proxies that can forward the request without altering them in any way. At the same time, other non-transparent proxies change the request before delivering it.

Functions performed by proxies:

  1. Caching: Storing information for future use.
  2. Filtering: Antivirus scan, parental control, etc.
  3. Load Balancing: Among multiple servers for improving performance.
  4. Authentication: Verification for giving access.
  5. Logging: Like storing previous information.

 

Interaction between Components (Source: MDN Docs)

HTTP Request:

How does the server know which information it has to serve? 
It is through an HTTP request that the web browser sends. Each request contains encoded data that carries information. Let us look at the structure of a request.

Each request contains:

HTTP Version Type:
It specifies the version of HTTP being used so that it can be interpreted accordingly. 

URL:
URL (Uniform Resource Locator) is used to locate a resource on the internet. It is commonly known as Web Address.

The HTTP Method:
Sometimes when we use HTTP as a verb, it refers to the action that a typical HTTP request expects from the server in question. 

 

Some of the most common HTTP methods are given below:

HTTP Method

Description

GET It fetches the information from the server.
POST It sends information to the server.
HEAD It retrieves the header data and not the entire response body.
PUT It works similarly to POST. It is used when we have to replace an existing entity completely. 
PATCH This is used when we have to update data partially.
DELETE It deletes the server's representation of resources. 
OPTIONS It returns data specifying different methods specifying operations performed by them.

 

HTTP Request headers:
They communicate information about the browser that the client is using and what data is being requested. They are included in every HTTP request. 

HTTP Request Body:
It is the body of the request. It contains information submitted to the webserver, like email or password, or the data the client can't find submitted through forms.

HTTP Response:

The response is the message that clients or browsers receive as an answer to their request. Like a response, request also has a specific structure:

HTTP status code

This is a three-digit code used to verify if the request has been successfully executed. 

1xx: Indicates an informational response.

2xx: Indicates success

3xx: Indicates redirection

4xx: Indicates client error

5xx: Indicates server error

Suppose the status code is 400 or 500. In that case, the webpage will not be displayed. 4 signifies an error on the client-side, and 5 means an error on the server-side. 

HTTP response headers
They contain some vital information like language and format of data being sent as a response.

HTTP body (optional)
This generally contains the requested information in the cases it has been requested. This is HTML data in most web pages.

HTTP Flow:

Steps to communicate with the server:

  1. A TCP (Transmission Control Protocol)  connection is required for the communication. 
  2. The next step is to send an HTTP message. They are almost always human-readable.
     

Example:

GET / HTTP/1.1

Host: www.example.com

3. And the final step is to read the response from the server. 

Example: 

HTTP/1.1 200 OK

Date: Fri, 23 September 2021 14:43:21 GMT

Content-Type: text/html; charset=UTF-8

Content-Length: 209

Last-Modified: Sun, 07 Feb 2021 22:51:33 GMT

Server: Apache/1.3.3.7 (Unix) (Red-Hat/Linux)

ETag: "3f90f-1c6-3e1cb03b"

Accept-Ranges: bytes

Connection: close

Features of HTTP:

  1. It is simple and easy to understand.
  2. HTTP is stateless. That means that there is no link between two requests being carried out at the same time.
  3. It is extensible. 
  4. Any type of content can be shared between the client and server as long as both are compatible with it.
  5. After the exchange of data, the client and server are no longer connected with each other.

Advantages of HTTP:

  1. Network congestion is less due to fewer TCP connections.
  2. It allows HTTP-Pipelining of request and response.
  3. The error can be reported without closing the connection.
  4. Low memory usage and CPU usage.
  5. Handshaking is done only at the initial stage. There is no need for any subsequent handshakes, and hence latency is reduced.

Disadvantages of HTTP:

  1. High Power usage for establishing communication and data transfer.
  2. It is not optimized for cell phones.
  3. It is not encrypted or secure.
  4. The client does not close communication until complete data has not been transferred. Hence the server is unavailable for that time.
  5. It does not offer a reliable exchange of data.

Functions of HTTP:

  1. Caching: Document caching is controlled by HTTP. 
  2. Relaxing Origin Constraints: Web Browsers allow only the pages of the same origin to access all the information of a web page due to privacy reasons. This is a burden for the server and can affect performance.HTTP headers can relax this separation, allowing documents to be assembled from the information of different domains.
  3. Authentication: Basic authentication can be provided by HTTP to give protection to the pages.
  4. Proxy and Tunneling: HTTP requests cross a network barrier by going through proxies as servers or clients often hide their true IP addresses.

Frequently Asked Questions

What are Persistent Connections?

As we saw above, the connection between client and server is lost after a request-response pair. But a mechanism was introduced in HTTP/1.1 in which connection can be reused for more than one request. This is called Keep-Alive Mechanism, and the network communication channel is called a persistent connection.

What is the difference between HTTP and FTP?

FTP is a File Transfer Protocol, whereas HTTP is HyperText Transfer Protocol. FTP is generally used for transferring large files and HTTP for smaller files like web pages.

What is the difference between TCP and HTTP?

TCP (Transmission Control Protocol) is used to establish a connection between server and client. In contrast, HTTP is used for actual communication.

Is HTTP the web?

No, HTTP is a protocol used to load web pages by creating requests. It is known as the foundation of the World Wide Web.

What is the difference between HTTP and HTTPS?

HTTP with encryption is HTTPS. For detailed information, check out the blog, What is the difference between HTTP and HTTPS

Conclusion

This blog discussed HTTP definition, HTTP components, HTTP request structure, and response structure. Then we looked at some features, functions, advantages, and disadvantages of HTTP. And finally, we discussed the HTTP flow. 

Readers start your web development journey now with Intro to HTMLIntro to CSS, and JavaScript Introduction.

If you are preparing for your next web development interview, check out the blogs, 25 CSS Interview Questions, and 30 JavaScript interview questions.

We hope you found this blog helpful. Feel free to let us know your thoughts in the comments section.

Live masterclass