HTTP
Definition
HTTP
- In plain English
- HTTP is the set of rules browsers and servers use to format requests and responses.
- Think of it like
- It is like a standard order form that every restaurant agrees to read.
Stateless
- In plain English
- Stateless means each request carries everything the server needs, so the server does not have to remember earlier requests.
- Think of it like
- It is like a ticket counter where you show your booking reference each time.
Why it exists
Without a shared message format, every client and server pair would need its own rules. HTTP gives both sides common ways to describe an action, attach information and report the outcome.
Start with readable HTTP/1.1 messages. HTTP/2 and HTTP/3 pack messages differently but keep the same methods and status meanings.
Cookie
- In plain English
- A cookie is a small piece of data the browser stores and sends on later requests that match its scope.
- Think of it like
- It is like a cloakroom ticket you show to collect your coat.
A login cookie references saved login data. Any server with that data can answer. Each request stands alone, even when the app stores user information.
How it works
Method
- In plain English
- An HTTP method is the verb of a request that says what you want done, such as GET to read.
- Think of it like
- It is like choosing dine in or takeaway on an order form.
Header
- In plain English
- A header is a labelled field of extra information sent with a request or response.
- Think of it like
- It is like notes on the outside of an envelope.
GET /menu HTTP/1.1
Host: cafe.example
Accept: application/json
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 17
{"items":["tea"]}| Method | Typical action | Same intended effect when repeated? |
|---|---|---|
| GET | Read | Yes; reading must not ask to change data |
| POST | Create or submit | Not guaranteed |
| PUT | Replace | Yes |
| PATCH | Change part | Depends on the change |
| DELETE | Remove | Yes; response status can differ |
Status code
- In plain English
- A status code is a three-digit number in the response that says how the request went.
- Think of it like
- It is like a parcel tracking status saying delivered, returned or lost.
| Family | Codes and meaning |
|---|---|
| 2xx: success | 200 OK; 201 Created |
| 3xx: redirect or reuse | 301 Moved Permanently; 304 Not Modified |
| 4xx: problem with the request | 400 Bad Request; 401 Unauthorized; 403 Forbidden; 404 Not Found; 409 Conflict; 429 Too Many Requests |
| 5xx: server failure | 500 Internal Server Error; 503 Service Unavailable |
The client sends GET /menu to the server. The server returns 200 OK with JSON data.
Examples
Borrow a drill
You browse drills and request a loan in a library of things.
Read with GET, submit with POST, and inspect the status before showing success. A conflict means the server understood the request but current inventory prevents it.
GET /items?category=drills HTTP/1.1
Host: tools.example
HTTP/1.1 200 OK
POST /loans HTTP/1.1
Host: tools.example
Content-Type: application/json
{"itemId":"drill-7"}
HTTP/1.1 201 Created
Location: /loans/91
HTTP/1.1 409 ConflictThe insight
Methods and status codes form a vocabulary both sides already know.
Distinguish blood-stock errors
Your hospital client asks a blood bank for available units.
Return 401 for missing or invalid login details. Return 403 when a signed-in caller lacks permission for another region. Return 404 for an unknown blood product.
The insight
Status codes tell clients whether to sign in, ask for permission, or fix the request.
Serve flashcards from four servers
Each flashcard request includes proof of login so any of four servers can answer.
ETag
- In plain English
- An ETag is a short version label the server attaches to a response so the client can later ask whether it has changed.
- Think of it like
- It is like a revision label on a study handout.
Each server checks the login proof or reads shared login data. Send the saved ETag in the If-None-Match header. If the deck is unchanged, a 304 response avoids sending it again.
A phone sends requests carrying a login token to Server 1, Server 2, Server 3, and Server 4.
The insight
Independent requests let you spread the work across servers.
Trade-offs
Pros
- Reuse widely supported tools.
- Inspect readable HTTP/1.1 exchanges.
- Reuse cacheable responses.
- Spread independent requests across servers.
Cons
- Headers add extra data.
- Ordinary exchanges need a client request.
- Many small actions require many requests.
Use when
- Serve web pages and public APIs.
- Use familiar request and response behavior.
Avoid when
- Tiny high-frequency messages dominate.
- The server needs an ongoing push channel.
Quick check
Takeaways
- HTTP = shared request/response format.
- Methods say what, status codes say how it went.
- Stateless application servers are easier to multiply.