How does HTTP works?

HTTP is a TCP/IP-based application layer communication protocol that standardizes how clients and servers communicate with each other. It defines how content is requested and transmitted across the internet. By application layer protocol, It relies on the underlying TCP/IP protocol for sending requests and receiving responses between clients and servers. Here's a brief description of how HTTP works:

process

  • Client sends a request: The process begins when a client, typically a web browser, sends a request to a web server. The request includes a specific HTTP method (e.g., GET, POST, PUT, DELETE) and a Uniform Resource Locator (URL) that identifies the desired resource.

  • Connection Establishment: Before the actual data transfer occurs, the client and server establish a TCP/IP connection. TCP (Transmission Control Protocol) provides a reliable and ordered data transfer between the two endpoints.

  • Server processes the request: Upon receiving the request, the web server examines the URL and determines the appropriate action to take. It retrieves the requested resource or performs the necessary operations based on the HTTP method specified.

  • Server returns an response: After processing the request, the server generates an HTTP response. The response contains a status code indicating the outcome of the request (e.g., 200 OK for a successful request, 404 Not Found for a missing resource). It also includes the requested data or any additional information required by the client.

  • Client receives the response: The client receives the HTTP response containing the requested data and the accompanying status code. It processes the response and displays the content to the user or performs further actions based on the received data.

  • Connection closure: Once the client has received the response, the HTTP connection can be closed, or it can be reused for subsequent requests. The client may send additional requests to the server for further resources or interactions, following the same process of sending requests and receiving responses.

HTTP is a stateless protocol, meaning that each request-response cycle is independent and does not retain information from previous interactions. To maintain state or enable more complex interactions, additional techniques like cookies or session tokens can be used.

Overall, HTTP provides a standardized way for clients and servers to communicate, enabling the retrieval and exchange of data that powers the World Wide Web.

NB: The information presented in this blog post is based on my personal learning and research from various sources, including the internet and other reference materials.

Reference:
educative.io
roadmap.sh