HTTP — Methods, Status Codes, Headers, HTTPS, TLS, HTTP/2 & 3
HTTP — Methods, Status Codes, Headers, HTTPS, TLS, HTTP/2 & 3
🎯 What you'll be able to do after this lesson
After finishing this lesson, you'll be able to confidently do the following three things.
- ▸✅ Core changes across HTTP 1.0 → 1.1 → 2 → 3
- ▸✅ Idempotency of GET, POST, PUT, DELETE, and PATCH
- ▸✅ How Cache-Control, ETag, and 304 caching work
Keep the learning objectives as a checklist, and close the lesson once you can answer all of them.
HTTP Methods, Status Codes, and Headers
HTTP Methods (8 total):
Idempotency = sending the same request N times has the same effect as sending it once. Outside of payments and POST, all methods should be idempotent.
HTTP Status Codes (5 groups):
Common points of confusion:
- ▸401 = Not authenticated (login required)
- ▸403 = Authenticated but not authorized
- ▸404 = Resource not found (or hidden for authorization purposes)
Key HTTP Headers:
HTTPS + TLS 1.3 Handshake
HTTPS = HTTP + TLS. Plain HTTP exposes all content if packets are intercepted.
TLS 1.3 Handshake (1-RTT, standardized in 2018):
3-Step Certificate Validation:
1. Trust: Is the issuer a trusted CA? (browser's built-in CA list)
2. Validity: Not expired? Not revoked (CRL/OCSP)?
3. Match: Does the domain match? (*.example.com ↔ api.example.com)
Forward Secrecy (required in TLS 1.3):
- ▸Generates a new key each session
- ▸Even if the server key is compromised, past traffic cannot be decrypted
HTTP/1.1 vs 2 vs 3:
HTTP/2 Multiplexing — multiple streams over a single TCP connection:
- ▸HTTP/1.1: only 6 concurrent connections (browser limit)
- ▸HTTP/2: unlimited streams on 1 connection. Solves Head-of-Line blocking
HTTP/3 (QUIC) — overcomes TCP limitations:
- ▸Solves TCP Head-of-Line blocking (one lost packet blocks everything)
- ▸0-RTT reconnection (PSK)
- ▸Maintains connection across mobile IP changes
HTTP Caching — Cache-Control, ETag, and 304
Why caching matters
Don't re-fetch the same resource every time — it improves bandwidth, server load, and perceived performance.
Cache-Control — the modern standard
6 commonly used directives
Real-world patterns
ETag — a fingerprint to check for changes
If the ETag matches, no body is sent — saving bandwidth. 1 MB body → 0 KB response.
Last-Modified — the old way
Less precise than ETag (second-level granularity). Modern servers prefer ETag.
Browser Cache vs CDN Cache
- ▸Browser cache: stores
privateorpublic. Your machine only. - ▸CDN cache: stores
publiconly. Shared across global edge servers.
Use the Vary header to specify which request differences should produce separate cache entries:
stale-while-revalidate — zero latency + freshness
Fresh for the first 60 seconds. From 60–360 seconds, serve the stale response immediately and revalidate in the background. The user gets an instant response, and the next request gets fresh data.
Next.js and TanStack Query use this strategy internally.
🤖 Try asking AI
- ▸"Set up next.config.js in Next.js to cache static files for 1 year and set no-cache for HTML"
- ▸"Add a 60-second cache + stale-while-revalidate 300 header to this API response"