Hypertext Transfer Protocol - The Foundation of Web Communication
HTTP is the foundation of data communication on the World Wide Web. It follows a client-server model where a client (typically a web browser) sends a request to a server, which then processes the request and returns an appropriate response.
Every HTTP interaction consists of a single request from client to server followed by a single response from server to client. This simple model enables the entire web to function.
Request Line: Contains the method (GET), path (/index.html), and HTTP version (HTTP/1.1)
Headers: Metadata about the request including host, client capabilities, and preferences
Body: Optional data sent with POST, PUT, PATCH requests
Status Line: HTTP version, status code (200), and reason phrase (OK)
Headers: Server information, content type, length, and caching directives
Body: The actual content (HTML, JSON, images, etc.)
| Component | Description | Example |
|---|---|---|
| Scheme | Protocol used (http or https) | https:// |
| Host | Domain name or IP address | www.example.com |
| Port | Port number (optional, default 80/443) | :8080 |
| Path | Resource location on server | /path/to/resource |
| Query | Parameters passed to resource | ?key1=value1 |
| Fragment | Section within resource | #section1 |
HTTP defines several methods (verbs) that indicate the desired action to be performed on the identified resource. According to RFC specifications, methods are case-sensitive and should be uppercase. [^5^]
Safe & Idempotent
Retrieves a resource from the server. Should not have side effects on server state.
Not Safe, Not Idempotent
Submits data to be processed (e.g., form submission, creating a resource).
Idempotent
Updates or replaces an existing resource with the request payload.
Idempotent
Removes the specified resource from the server.
Not necessarily Idempotent
Applies partial modifications to a resource (unlike PUT which replaces entirely).
Safe & Idempotent
Identical to GET but returns only headers, no body. Useful for checking existence.
Status codes are three-digit integers where the first digit defines the class and the last two digits do not have categorization roles. According to MDN Web Docs, there are five standard classes. [^2^]
HTTP headers provide additional information about the request or response, or about the object sent in the message body. They are key-value pairs separated by colons.
| Header | Purpose | Example |
|---|---|---|
| Host | Specifies the server domain (required in HTTP/1.1+) | Host: www.example.com |
| User-Agent | Identifies the client software | Mozilla/5.0 (Windows NT 10.0...) |
| Accept | Indicates preferred content types | text/html, application/json |
| Content-Type | Media type of request body | application/json |
| Authorization | Credentials for authentication | Bearer eyJhbGciOiJIUzI1... |
| Cookie | Sends stored cookies to server | sessionid=abc123; user=john |
| Header | Purpose | Example |
|---|---|---|
| Content-Type | Media type of response body | text/html; charset=utf-8 |
| Content-Length | Size of response body in bytes | 348 |
| Location | Redirect target URL | /new-path/resource |
| Set-Cookie | Sets a cookie on client | sessionid=xyz789; Path=/ |
| Cache-Control | Caching directives | max-age=3600, no-cache |
| WWW-Authenticate | Authentication method required | Bearer realm="api" |
Content-Type headers so clients know how to parse the response. For JSON APIs, use application/json.
HTTP has evolved significantly since its inception in 1991, with each version addressing performance and security limitations of its predecessor. [^1^][^7^]
The one-line protocol. Only supported GET method, no headers, just raw HTML. Extremely simple but limited.
Added headers, status codes, and additional methods (POST, HEAD). Still created new TCP connection for each request.
Introduced persistent connections (keep-alive), pipelining, caching mechanisms, and chunked transfer encoding. Still suffers from head-of-line blocking. [^8^]
Binary protocol with multiplexing, header compression (HPACK), server push, and stream prioritization. Runs over TCP but solves HTTP-level head-of-line blocking. [^4^]
Uses QUIC over UDP instead of TCP. Eliminates transport-level head-of-line blocking, enables 0-RTT connections, and mandates TLS 1.3 encryption. [^6^]
| Feature | HTTP/1.1 | HTTP/2 | HTTP/3 |
|---|---|---|---|
| Transport | TCP | TCP | QUIC (UDP) |
| Multiplexing | ❌ No | ✅ Yes | ✅ Yes |
| Head-of-Line Blocking | ❌ TCP & HTTP level | ⚠️ TCP level only | ✅ Eliminated |
| Header Compression | ❌ No | ✅ HPACK | ✅ QPACK |
| Server Push | ❌ No | ✅ Yes | ✅ Yes |
| Encryption | ⚠️ Optional | ⚠️ Optional (TLS) | ✅ Mandatory TLS 1.3 |
| Connection Setup | Multiple RTTs | 2-3 RTTs | 0-1 RTT (0-RTT resumption) |
HTTPS (HTTP Secure) encrypts HTTP communications using Transport Layer Security (TLS). Modern versions:
| Header | Purpose |
|---|---|
| Strict-Transport-Security (HSTS) | Forces HTTPS connections for specified time |
| Content-Security-Policy (CSP) | Prevents XSS by controlling resource loading |
| X-Frame-Options | Prevents clickjacking attacks |
| X-Content-Type-Options | Prevents MIME type sniffing |
| Referrer-Policy | Controls referrer information leakage |
Test your understanding of HTTP concepts with these practice questions: