Introduction to http
Hypertext Transfer Protocol (HTTP) is the foundational protocol upon which the entire web relies. HTTP enables us to load web pages, making it essential to understand its workings.
HTTP is an application-layer protocol used to send documents, such as HTML. It facilitates communication between web browsers and web servers.
How HTTP Works
A typical HTTP flow involves a client making a request to a server, which then sends a response back to the client. This means that requests are initiated by the recipient (the client), usually a web browser. The complete document object model (DOM) is reconstructed from various sub-documents fetched, including text, layout of the web page, images, videos (static resources), scripts, and more.
Let’s delve deeper into HTTP requests and their components.
What is in an HTTP Request?
An HTTP request is how a client asks for information from a web server. When you enter a URL in your browser's address bar, click on a link, or submit a form on a webpage, your browser generates an HTTP request to the server hosting the website.
An HTTP request carries several pieces of encoded data that convey different types of information, including:
Method: The action to be performed.
Request Headers: Metadata about the request.
Optional HTTP Body: Additional data sent with the request.
HTTP Version: The version of HTTP being used.
Let’s dive deeper into how these requests work and what role other components plays.
HTTP Methods
An HTTP method serves as a set of instructions telling the server what action to take when you request something. Think of them as action words, often referred to as HTTP verbs. The two main methods are GET and POST:
GET: This method requests a data representation of the specified resource. Requests using GET can retrieve data without altering it.
POST: This method sends data to a server so it may change its state. It is commonly used in HTML forms to submit information or data to the server.
there are other methods like PUT , PATCH ,DELETE ,CONNECT . like GET request fetches the data from server on a PUT is generally Made to update the existing data , the same can be done over a POST request too but its not a good practice.
HTTP Request Headers
Request headers contain text information stored in key-value pairs and are included in every HTTP request (and response). These headers communicate essential information, such as what browser the client is using and what data is being requested.
What is in an HTTP Request Body?
The body of an HTTP request carries the actual data being sent to the server. This includes information like usernames, passwords, or any other data entered into a form on a website. This data is crucial for the server to process and respond accordingly.
For example, when you submit a form on a webpage, details like your name and email address are included in the body of the HTTP request sent to the server for processing. This separation of headers (containing metadata) and body (containing actual data) allows for efficient communication between clients and servers on the web.
What is in an HTTP Response?
An HTTP response is what clients receive from the server in return for an HTTP request. These responses provide information about what the client requested. An HTTP response consists of three parts:
1.Status Code
2.Response Headers
3.Body
Let’s break these down further:
HTTP Status Code
Status codes are three-digit codes that provide context about the result of an HTTP request made by a client to a server. There are five categories of status codes:
- 1.1xx Informational
- 2.2xx Success
- 3.3xx Redirection
- 4.4xx Client Error
- 5.5xx Server Error
Each category has specific meanings:
2xx (Success): Starting with '2' indicates a successful request. For instance, '200 OK' signifies that the client's request for a webpage was successfully completed.
4xx (Client Error): Starting with '4' means there was an error on the client side. A common example is '404 NOT FOUND,' which occurs when there’s a mistake in the URL.
5xx (Server Error): Starting with '5' indicates an error on the server side. For example, '500 Internal Server Error' suggests something went wrong within the server while processing the request.
1xx (Informational): Starting with '1' denotes an informational response but is less commonly encountered during regular web browsing.
3xx (Redirection): Starting with '3' signifies redirection and instructs the client to take further action to complete the request.
HTTP Response Headers
Response headers provide additional context about the response and the data being sent in the response body.

HTTP Response Body
When you ask a website for something using your browser—like opening a webpage—the server typically sends back a response. If everything goes well (indicated by a '200 OK' status), the server places the requested information in the response body. For most web content, this information is formatted as HTML—the language browsers use to create webpages. Your browser then takes that HTML and renders it into the webpage you see.