HTTP Methods
HTTP methods define the intent of a request. The key properties are safety (no side effects) and idempotency (repeating the request produces the same result). REST APIs rely on these semantics for predictable behaviour.
Status Codes
Status codes are grouped by their first digit. A well-designed API returns the most specific code available, not just 200 for everything or 500for client mistakes.
Headers
Headers carry metadata about the request or response. They control content negotiation, authentication, caching, and CORS. Keep custom headers prefixed with X-(deprecated by RFC 6648) or use a vendor namespace like My-App-Request-Id.
| Request Headers | Response Headers |
|---|---|
| Authorization: Bearer <token> | WWW-Authenticate: Bearer realm=... |
| Accept: application/json | Content-Type: application/json |
| Content-Type: application/json | Cache-Control: max-age=3600 |
| If-None-Match: "etag-value" | ETag: "etag-value" |
| Origin: https://example.com | Access-Control-Allow-Origin: * |
| Accept-Encoding: gzip, br | Content-Encoding: gzip |
Caching
HTTP caching eliminates redundant network round-trips. The browser checks its cache before sending a request; if valid, it serves the cached copy. The server controls cache behaviour through Cache-Control and ETag headers.
# Cache-Control directives
# Public CDN cache for 1 day, stale-while-revalidate for 1 hour
Cache-Control: public, max-age=86400, stale-while-revalidate=3600
# Private (browser only), no CDN caching
Cache-Control: private, max-age=3600
# Never cache (auth pages, real-time data)
Cache-Control: no-store
# Cached but must revalidate every request
Cache-Control: no-cache
# Conditional request headers (sent by browser)
If-None-Match: "abc123" # ETag from previous response
If-Modified-Since: Thu, 01 Jan 2026 00:00:00 GMTIf-None-Match with a cached ETag, the server returns 304 Not Modifiedinstead of re-sending the full body, saving bandwidth.HTTP/2 vs HTTP/3
HTTP/2 introduced multiplexing over a single TCP connection, eliminating head-of-line blocking at the HTTP layer. HTTP/3 replaces TCP with QUIC (UDP-based), solving transport-level head-of-line blocking and improving performance on lossy connections.
| HTTP/2 | HTTP/3 |
|---|---|
| Transport: TCP + TLS | Transport: QUIC (UDP-based) |
| Multiplexed streams over one connection | Independent QUIC streams, no TCP HoL blocking |
| Header compression: HPACK | Header compression: QPACK |
| Connection setup: 1–2 RTT | 0-RTT reconnects for returning clients |
| ~97% browser support | ~95% browser support (still growing) |
Alt-Svc header. You typically get HTTP/3 for free by using a CDN — no application code changes needed.