What is HTTP Request?
An HTTP request is the method in which your client (your browser, mobile app) communicates with the server. It stands for HyperText Transfer Protocol.
Let’s try to understand this HyperText Transfer Protocol word by word:
HyperText: HyperText simply refers to the text that contains links to other texts (or resources). It is called HyperText because it is beyond or above the traditional text as it has the ability to take you from one resources to another.
Transfer: Transfer as name suggest’s refer to the process of moving data from one location to another.
Protocol: A protocol is a set of rules or standards that define how two parties or entities (browser and web server) should communicate.
How does HTTP works?
Before diving into the concepts of HTTP, let’s try to imagine it with the help of restaurant analogy:
Let suppose you walk into the restaurant.
You call the waiter and gave your order.
The waiter takes your order to the chef and chef prepares your order in the kitchen.
And finally, the waiter brings you back your order.
In the same way HTTP request works:
You open the browser.
You gave your order to the browser.
The browser sends your request to server and server processes your request.
And finally, the server send the HTTP response to the browser and browser bring it to you.
Is HTTP stateless or stateful Protocol?
First let’s understand what is stateless protocol and stateful protocol:
Stateless: In simple terms, if state is not maintained for a request on server and every request is treated like it is a first request, then it is said a stateless protocol.
Stateful: And if state is maintained for a request on server it is called stateful protocol.
Now, coming back to our question, HTTP is a stateless protocol because in this server does not maintain any state for incoming requests and each request is treated like a first request.
HTTP Headers
HTTP Headers are the key-value pairs send as a part of an HTTP request or response. They provide additional information about the request or response.
Types of HTTP Headers
There are basically two main types of headers:
Request Headers
Send by the client to the server to provide additional information about the request.
For example:
User-Agent
: Refers to client (or user) browser.Authorization
: Provides credentials for authentication.Host
: Specifies the domain name of the server being requested.
Response Headers
Send by the server to the client to provide additional information about the response.
For example:
Set-Cookie
: Sends cookies from the server to the client.
HTTP Request-Response Model
The HTTP request-response model is the core communication method in the HTTP protocol to exchange data between a client (e.g., browser) and a server.
Steps in the Model:
Client Sends a Request:
The client initiates communication by sending an HTTP request to the server.
Server Processes the Request:
The server interprets the request, performs the necessary operations (e.g., querying a database, rendering a page), and prepares a response.
Server Sends a Response:
The server sends back an HTTP response to the client.
HTTP Response Codes
HTTP response codes are three-digit numbers send by the server indicating the status of the request. They are grouped into five categories:
1. Informational (100–199):
These codes indicate that the server has received the request and is continuing to process it.
Examples:
100 Continue
: The initial part of the request is received, and the client can continue sending.
2. Success (200–299):
These codes indicate that the request was successfully received, understood, and processed.
Examples:
200 OK
: The request was successful, and the response contains the requested content.201 Created
: The request resulted in the creation of a resource.
3. Redirection (300–399):
These codes indicate that the client must take additional actions to complete the request.
Examples:
301 Moved Permanently
: The resource has been permanently moved to a new URL.
4. Client Error (400–499):
These codes indicate an error caused by the client.
Examples:
400 Bad Request
: The server couldn’t understand the request due to malformed syntax.401 Unauthorized
: Authentication is required and has failed or has not been provided.403 Forbidden
: The server understood the request but refuses to authorize it.404 Not Found
: The requested resource could not be found.
5. Server Error (500–599):
These codes indicate an error on the server side.
Examples:
500 Internal Server Error
: A generic error indicating that the server encountered an issue.501 Not Implemented
: The server does not support the requested functionality.503 Service Unavailable
: The server is temporarily unavailable (e.g., due to overload or maintenance).