HTTP — The Language of the Web
Request and response cycle, headers, and protocol basics
Skills taught: web.http-basics, web.request-structure, web.response-structure, web.headers
HTTP is text
HTTP (HyperText Transfer Protocol) is the protocol that browsers and servers use to communicate. Despite sounding technical, an HTTP message is just structured text — you can read it by eye. Every network request you will ever make follows this format.
The HTTP request
GET /users/42 HTTP/1.1
Host: api.example.com
Accept: application/json
Authorization: Bearer eyJhbGciOiJSUzI1NiJ9...
Accept-Encoding: gzip, br
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)
(no body for GET requests)
- Request line — method (
GET), path (/users/42), protocol version (HTTP/1.1) - Headers — key-value pairs, one per line.
Host is required; others are optional. - Blank line — signals the end of headers
- Body — optional. GET requests have no body. POST/PUT/PATCH carry data here.
The HTTP response
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 97
Cache-Control: max-age=3600
X-Request-ID: f47ac10b-58cc-4372-a567-0e02b2c3d479
{
"id": 42,
"name": "Alice Smith",
"email": "alice@example.com",
"role": "admin"
}
- Status line — protocol version, status code (
200), reason phrase (OK) - Response headers — metadata: content type, size, caching rules
- Blank line — signals the end of headers
- Response body — the actual data: HTML, JSON, an image, etc.
Important request headers
Host: api.example.com → Required. Which server to talk to.
Accept: application/json → What response format the client wants.
Content-Type: application/json → What format the request body is in.
Authorization: Bearer <token> → Credentials (API key, JWT, etc.).
Cookie: session=abc123 → Sends stored cookies to the server.
If-None-Match: "abc123" → Conditional GET — only send if changed.
Origin: https://app.example.com → Where the request came from (CORS).
Important response headers
Content-Type: text/html; charset=utf-8 → Body format.
Content-Length: 4823 → Body size in bytes.
Cache-Control: max-age=86400, public → Cache for 24 hours.
Set-Cookie: token=abc; HttpOnly; Secure → Set a cookie in the browser.
Location: /users/42 → Where to redirect (for 3xx).
Access-Control-Allow-Origin: * → CORS: any origin may read this.
X-Request-ID: uuid-here → Custom header (X- prefix = non-standard).
Tip: HTTP is stateless — the server remembers nothing between requests. Cookies and Authorization headers are how state ("I am logged in") travels from request to request.
Frequently Asked Questions
What is the difference between HTTP/1.1, HTTP/2, and HTTP/3?
HTTP/1.1 is text-based; each request needs its own TCP connection (or queues behind others). HTTP/2 is binary and multiplexes many requests over one connection. HTTP/3 uses QUIC (over UDP) for lower latency, especially on mobile networks. The method/status code/header semantics are the same across all versions — only the transport changes.
What are X- headers?
Headers starting with X- are non-standard (custom) headers — X stands for 'extension'. Examples: X-Request-ID (trace an individual request), X-Rate-Limit-Remaining (how many API calls you have left), X-Powered-By (the server software). The X- convention is deprecated in new specifications, but still widely used in practice.
Can I see raw HTTP messages?
Yes. Open DevTools (F12) → Network tab → click any request → click 'Headers'. You will see the exact request and response headers. For the raw request body, click the 'Payload' or 'Request' tab.