Every time we open a website, or make an API call, something fundamental happens behind the scenes – an HTTP Request is made.
It's one of the most essential building blocks of the internet. In this article, we will break down what an HTTP request is, how it works, and why it matters in system design and backend development.
What Is an HTTP Request?
HTTP (Hypertext Transfer Protocol) is the communication protocol that allows clients (like browsers or mobile apps) to talk to server.
When we type a URL or click a button that fetches data – our browser sends an HTTP request to a web server.
The server then processes it and sends back an HTTP response.
In Simple terms:
HTTP request: “Hey server, here's what I need.”
HTTP response: “Here's what you asked for.”
The Structure of an HTTP Request
Every HTTP request follows a clear, structured format. It has three main parts:
<Request-Line>
<Headers>
<Body>
1 Request Line
This is the first line of the request, which tells the server what action to perform and where.
Format:
<Method> <Request-URI> <HTTP-Version>
Example:
GET /api/users HTTP/1.1
Here:
GET: Method (what you want to do)/api/users: Target resource (URL or path)HTTP/1.1: Version of HTTP protocol used
2 Headers
Headers are key-value pairs that carry metadata about the request – who's sending it, what type of data it includes, and how it should be handled.
Format:
Header-Name: Header-Value
Example:
Host: example.com
User-Agent: Mozilla/5.0
Accept: application/json
Content-Type: application/json
Authorization: Bearer <token>
These headers tell the server details like:
- Which domain you are requesting.
- Which browser or client is sending it.
- What kind of response format you expect.
- If you are authorized to access the resource.
3 Blank Line
There's always a blank line (i.e., \r\n) after header – it signals that header section is over and the body (if any) starts next.
4 Body (Optional)
The body contains data sent to the server – typically used in POST, PUT, or PATCH requests.
It can be:
- Form data
- JSON data
- Multipart data
- Binary (images, videos, etc.)
Example (JSON body):
{
"name": "TheJat",
"email": "admin@thejat.in"
}
Common HTTP Methods
Each HTTP method defines a specific type of action we want to perform:
| Method | Purpose | Example Use Case |
|---|---|---|
| GET | Retrieve data | Fetch a list of users |
| POST | Create new data | Add a new user |
| PUT | Replace data | Update user details |
| PATCH | Modify data | Update one field |
| DELETE | Remove data | Delete a user |
| OPTIONS | Ask what’s allowed | API capability discovery |
Leave a comment
Your email address will not be published. Required fields are marked *
