HTTP Overview
HTTP - Overview
Section titled “HTTP - Overview”The Hypertext Transfer Protocol (HTTP) is an application-layer protocol designed for distributed, collaborative, and hypermedia information systems. It has served as the cornerstone of data communication for the World Wide Web since the early 1990s. HTTP is a flexible, stateless protocol that defines how messages are formatted and transmitted, and what actions web servers and browsers should take in response to various commands.
At its core, HTTP is a client-server, request-response protocol. Clients (e.g., web browsers, mobile apps) send requests to servers to access resources like HTML files, images, JSON data, etc. Servers process these requests and send back responses. While initially designed for hypertext documents, HTTP is now used to transfer any type of data. Traditionally, HTTP used TCP/IP port 80, but modern web communication almost exclusively uses HTTPS (HTTP Secure) on port 443, which encrypts HTTP traffic using TLS.
HTTP has evolved through several versions: HTTP/0.9 (rudimentary), HTTP/1.0 (added headers, methods), HTTP/1.1 (introduced persistent connections, pipelining, host header), HTTP/2 (binary protocol, multiplexing, header compression for performance), and HTTP/3 (uses QUIC over UDP for further performance gains). This tutorial focuses on the semantics largely established by HTTP/1.1, which are foundational to all later versions.
Core Features of HTTP
Section titled “Core Features of HTTP”Three fundamental features define HTTP’s simplicity and power:
- HTTP is connection-oriented but managed per transaction: In HTTP/1.0, each request often meant a new TCP connection. HTTP/1.1 introduced persistent connections (keep-alive by default), allowing multiple requests/responses over a single connection, significantly reducing latency. HTTP/2 and HTTP/3 further optimize connection usage with multiplexing. Despite persistent connections, the protocol operates on discrete request-response pairs.
- HTTP is media independent: HTTP can transmit any type of data (e.g., HTML, images, audio, video, JSON, XML) as long as both client and server can understand it. The
Content-Typeheader, using MIME types, specifies the data format, enabling clients to process the payload correctly. - HTTP is stateless: Each HTTP request from a client is independent and does not inherently link to previous requests. The server does not store any session context between requests from the same client by default. This statelessness simplifies server design and improves scalability. To maintain state (e.g., for user sessions or shopping carts), applications use techniques like cookies, tokens in headers (e.g.,
Authorization), or URL rewriting, which are managed on top of HTTP.
HTTP/1.1 standardized persistent connections. HTTP/2 introduced multiplexing over a single TCP connection, and HTTP/3 moved to QUIC (over UDP) for improved performance and reduced head-of-line blocking.
Basic Architecture
Section titled “Basic Architecture”HTTP operates on a client-server model. The client (user agent) sends a request, and the server returns a response. This interaction can be direct or mediated by intermediaries like proxies, gateways, or tunnels.
A typical web application architecture involving HTTP includes:
- Client (User Agent): Software that initiates requests, such as a web browser (Chrome, Firefox), a command-line tool (cURL, Wget), a mobile application, or an IoT device.
- Intermediaries (Optional): Devices or servers that sit between the client and origin server. Examples include:
- Server (Origin Server): The server that hosts the requested resource or provides the service. Examples include Apache, Nginx, IIS, or application servers running Node.js, Python, Java, etc.
Client
Section titled “Client”The HTTP client constructs and sends an HTTP request message. This message includes a request method (e.g., GET, POST), the target resource’s URI, the HTTP protocol version, various headers providing context (like acceptable content types or authentication credentials), and sometimes a message body (payload), all typically over a TCP/IP connection (or QUIC for HTTP/3). For HTTPS, a TLS handshake precedes HTTP message exchange.
Server
Section titled “Server”The HTTP server listens for incoming requests on a specific network port (e.g., 80 for HTTP, 443 for HTTPS). Upon receiving a request, it parses it, performs the requested action (e.g., retrieving a file, querying a database, executing business logic), and then constructs and sends back an HTTP response message. The response includes a status code indicating the outcome, headers with metadata about the response, and often a message body containing the resource representation or status information.