HTTP for Backend Engineers

In this blog, we're going to talk about HTTP, its methods, and some of the functionalities that make it one of the most important protocols for backend engineers.
Before diving into the individual methods and concepts, let's understand two ideas that sit at the heart of HTTP.
Stateless
Client-Server Model
Stateless
HTTP is a stateless protocol.
This means that every request made by a client is treated as an independent request. The server does not remember previous requests made by the same client.
For example, imagine you log in to a website.
You send your username and password to the server. The server validates your credentials and returns a response.
Now, when you make your next request, the server does not automatically know that you are the same user who just logged in.
HTTP itself doesn't remember the previous interaction.
So how do websites maintain continuity between requests?
This is where state management techniques come into play.
Cookies, sessions, and tokens are commonly used to maintain continuity where needed.
For example:
You log in.
The server validates your credentials.
The server creates a session or issues a token.
Your client sends that session identifier or token with subsequent requests.
The server uses it to identify you.
So while HTTP itself remains stateless, applications can build stateful behaviour on top of it.
Client-Server Model
HTTP follows a client-server model.
The client initiates a request and the server processes that request and sends back a response.
The client could be:
A web browser
A mobile application
Another backend service
A command-line tool
And the server is responsible for processing the request, performing the required business logic, communicating with databases or other services, and returning a response.
This separation is one of the reasons the client and server can evolve independently.
The client doesn't need to know how the server processes a request internally. It only needs to know how to communicate with it.
Why do we need a transfer protocol?
Imagine sending a request from your browser to a server.
The data needs to travel across multiple networks before reaching its destination.
We need a set of rules that defines:
How the request should be structured
How the server should understand it
How the response should be structured
How errors should be communicated
How different types of data should be represented
That's where HTTP comes in.
HTTP is an application-layer protocol that defines the semantics and structure of communication between clients and servers.
You don't need to remember every layer right now.
The important thing is that HTTP defines how the client and server communicate, while the underlying transport protocol is responsible for moving the data across the network.
HTTP Messages
Communication in HTTP happens through messages.
A client sends a request message to the server.
The server processes that request and sends back a response message.
A request generally contains:
Request Line
Headers
Blank Line
Optional Body
For example:
GET /users/luke HTTP/1.1
Host: droidcall.com
Accept: application/json
Authorization: Bearer <token>
Let's break this down.
Request Line
The request line contains:
The HTTP method
The path or resource being requested
The HTTP version
GET /users/luke HTTP/1.1
Here:
GETis the HTTP method/users/luke is the resource being requestedHTTP/1.1is the HTTP version
Request Headers
Headers provide additional information about the request.
For example:
Host: example.com
Accept: application/json
Authorization: Bearer <token>
Content-Type: application/json
Headers can communicate things like:
What type of response the client expects
What type of data is being sent
Authentication information
Caching instructions
Cookies
Information about the client
The request may also contain a body.
The body is generally used when the client needs to send data to the server.
For example:
POST /users HTTP/1.1
Content-Type: application/json
{
"name": "General Kenobi",
"email": "obiwan@example.com"
}
The server then processes the request and sends a response.
A response generally contains:
Status Line
Headers
Blank Line
Optional Body
For example:
HTTP/1.1 201 Created
Content-Type: application/json
{
"id": 66,
"name": "Sidious"
}
The status code tells the client what happened with the request.
For example:
200 OK→ The request was successful201 Created→ A resource was successfully created400 Bad Request→ The request was invalid401 Unauthorized→ Authentication is required or invalid403 Forbidden→ The client is not allowed to perform the action404 Not Found→ The requested resource does not exist500 Internal Server Error→ Something went wrong on the server
HTTP Methods
HTTP methods tell the server what the client wants to do with a resource.
GET
Used to retrieve data from the server.
GET /users/vader
A GET request should not modify the state of the server.
For example:
Fetching a user's profile
Fetching a list of products
Fetching a blog post
POST
Used to submit data to the server.
It is commonly used to create a new resource.
POST /users
With the request body:
{
"name": "Darth Vader"
}
The server might then create a new user.
PUT
Used to completely replace a resource.
For example, imagine we have this user:
{
"name": "Yoda",
"email": "Yoda@example.com",
"age": 700
}
Now we send:
PUT /users/66
With:
{
"name": "Grogu",
"email": "Grogu@example.com"
}
The server interprets this as a complete replacement of the resource.
PATCH
Used to partially modify a resource.
For example:
PATCH /users/kyber
With:
{
"email": "jedha@example.com"
}
Only the email field needs to be changed.
The rest of the resource remains unchanged.
So the simple distinction is:
PUT → Replace the resource
PATCH → Modify parts of the resource
DELETE
Used to delete a resource.
DELETE /users/66
The server can then remove the user with ID 66.
Idempotent and Non-Idempotent Methods
This is a concept that is extremely important when building reliable backend systems.
An operation is idempotent if making the same request multiple times has the same intended effect on the server as making it once.
For example:
PUT /users/66
With:
{
"name": "Sidious"
}
If you send this request once, the user's name becomes Aman.
If you send the exact same request ten times, the intended final state is still:
name = Aman
The final result is the same.
Therefore, PUT is idempotent.
The commonly used idempotent HTTP methods are:
GETHEADPUTDELETEOPTIONS
POST, on the other hand, is generally not idempotent.
Imagine:
POST /orders
If this creates a new order every time, sending the same request three times could create three separate orders.
So:
GET → Idempotent
PUT → Idempotent
DELETE → Idempotent
POST → Generally non-idempotent
PATCH → Generally non-idempotent
One important thing to understand is that idempotency describes the intended effect of an operation, not whether the response will be exactly identical every time.
For example, deleting a resource once might return 204 No Content, while repeating the same request might return 404 Not Found.
The operation is still considered idempotent if the intended state of the server remains the same after the first successful deletion.
Idempotency is particularly important when designing retries. If a request fails due to a network issue, the client may not know whether the server processed it or not. Retrying an idempotent operation is generally safer than retrying a non-idempotent operation.
OPTIONS
The OPTIONS method is used to discover the communication options available for a resource or server.
For example, a client can ask:
What HTTP methods are supported for this resource?
The server can respond with something like:
Allow: GET, POST, OPTIONS
OPTIONS is also heavily used in the CORS flow.
This brings us to the concept of a preflight request.
Preflight Request
You might remember from my previous blog that browsers enforce the Same-Origin Policy.
When a browser wants to make certain cross-origin requests, it may first send a preflight request to the server.
This preflight request uses the OPTIONS method.
The browser essentially asks:
"I want to make this request. Are you okay with it?"
For example:
OPTIONS /api/users HTTP/1.1
Origin: https://frontend.example.com
Access-Control-Request-Method: POST
Access-Control-Request-Headers: Authorization, Content-Type
The server can then respond:
Access-Control-Allow-Origin: https://frontend.example.com
Access-Control-Allow-Methods: POST
Access-Control-Allow-Headers: Authorization, Content-Type
If the server allows the request, the browser proceeds with the actual request.
A preflight request is generally triggered when the request is not considered a "simple request".
This can happen when:
The HTTP method is not
GET,HEAD, orPOSTThe request contains certain non-safelisted headers
The request uses certain content types that are not considered CORS-safelisted
For example, sending an Authorization header or using application/json as the content type can cause a preflight request.
The browser handles this process automatically.
HTTP Caching
Imagine that you request the same resource repeatedly.
For example:
GET /products
If the products don't change frequently, sending the request to the server every single time may be unnecessary.
HTTP provides caching mechanisms that allow clients and intermediary caches to reuse previously received responses.
This can:
Reduce the number of requests reaching the server
Reduce bandwidth usage
Improve response times
Reduce server load
HTTP caching uses headers such as:
Cache-Control
ETag
Last-Modified
Expires
For example:
Cache-Control: max-age=3600
This tells the client that the response can be reused for a certain period.
Another common mechanism is ETag.
The server sends a unique identifier for a particular version of a resource:
ETag: "abc123"
When the client requests the resource again, it can send:
If-None-Match: "abc123"
If the resource hasn't changed, the server can respond with:
304 Not Modified
The client can then reuse its cached copy instead of downloading the entire response again.
This is a really useful feature.
But caching can become complicated in production.
You need to think about:
How long data should be cached
What happens when the data changes
How caches are invalidated
Whether different users should receive different cached responses
Whether the cache is stored in the browser, a CDN, or a proxy
This is why applications sometimes use client-side data-fetching and caching libraries such as React Query.
However, React Query and HTTP caching are not replacements for each other.
They operate at different layers.
HTTP caching is part of the protocol and works through HTTP caching headers.
A library like React Query manages server state inside the client application. It can decide when to fetch data, when to reuse data, and when to refetch it.
So the two can actually work together.
Content Negotiation
A client and server may support multiple formats for the same resource.
For example, a client may prefer JSON:
Accept: application/json
Another client may request XML:
Accept: application/xml
This is where content negotiation comes into play.
The client communicates what formats it can understand, and the server selects an appropriate representation.
For example:
Accept: application/json
The server might respond:
Content-Type: application/json
The Accept header tells the server what the client wants to receive.
The Content-Type header tells the client what format the response actually contains.
This distinction is important.
Accept:
"What format can I understand?"
Content-Type:
"What format is this data in?"
Content negotiation can also involve things like:
Language
Character encoding
Compression
For example, a browser might tell the server:
Accept-Encoding: gzip, br
The server can then compress the response using a supported encoding.
SSL, HTTPS and TLS
Let's finish with something we use almost every day:
https://
You might have heard the terms SSL, HTTPS, and TLS used interchangeably.
But they are not exactly the same thing.
SSL
SSL stands for Secure Sockets Layer.
It was an older protocol designed to secure communication over a network.
SSL is now obsolete and should no longer be used.
TLS
TLS stands for Transport Layer Security.
It is the modern protocol used to secure communication between a client and a server.
TLS provides three important properties:
1. Encryption
The data exchanged between the client and server is encrypted.
So if someone intercepts the traffic, they should not be able to read the actual data.
2. Integrity
TLS helps ensure that the data is not modified while it is travelling between the client and server.
If someone tries to modify the data in transit, the tampering can be detected.
3. Authentication
TLS allows the client to verify the identity of the server.
This is where digital certificates come into play.
Your browser can verify that the server it is connecting to is actually the server it claims to be.
HTTPS
HTTPS stands for:
HTTP + TLS
HTTP defines how the client and server communicate.
TLS secures that communication.
So:
HTTP
+
TLS
=
HTTPS
When you visit a website using:
https://example.com
your HTTP communication is being sent over a TLS-secured connection.
This protects your data from being easily read or modified by attackers while it is travelling across the network.
And that's why you should always prefer HTTPS over plain HTTP.
That's it for this blog.
HTTP is one of those technologies that we use constantly but rarely think about.
Every time you open a website, fetch data from an API, submit a form, log in to an application, or upload a file, HTTP is usually involved somewhere in the communication.
Understanding HTTP properly gives you a much stronger foundation for understanding backend engineering.
And honestly, once you start looking at backend systems through the lens of requests, responses, methods, headers, caching, and transport protocols, a lot of the abstractions created by frameworks start making much more sense.
I'll continue exploring backend fundamentals in the next blog.
Thanks for reading!
About the author
- Just an engineer trying to build better software. This blog is my engineering journal, where I share backend concepts, system design, AI experiments, and the lessons I pick up while building real products.
Comments
Join the discussionNo comments yet. Be the first to comment.




