HTTP
Contents
HTTP
HTTP (Hypertext Transfer Protocol) is an application-layer protocol used for transmitting hypermedia documents, such as HTML, across the World Wide Web. It is the foundation of data communication on the web, enabling the fetching of resources such as web pages, images, stylesheets, and scripts.
HTTP is a request–response protocol between clients (usually web browsers) and servers. It was developed by Tim Berners-Lee in the early 1990s alongside the first web browser and server.
How HTTP Works
HTTP operates on a simple client-server model:
1. The client (e.g., a web browser) sends a request to a server for a resource (e.g., a webpage). 2. The server processes the request and returns a response (e.g., the HTML file, image, or error message).
HTTP typically uses port 80 by default.
HTTP Methods
HTTP defines several request methods (also called verbs), including:
- GET – Request data from a specified resource (most common).
- POST – Submit data to be processed (e.g., form submission).
- PUT – Update a resource with new data.
- DELETE – Remove a specified resource.
- HEAD – Request headers only (no body).
- OPTIONS – Describe communication options for the target resource.
- PATCH – Partially update a resource.
HTTP Response Codes
HTTP responses include status codes that indicate the result of the request:
- 1xx – Informational (e.g., 100 Continue)
- 2xx – Success (e.g., 200 OK, 201 Created)
- 3xx – Redirection (e.g., 301 Moved Permanently, 302 Found)
- 4xx – Client errors (e.g., 404 Not Found, 403 Forbidden)
- 5xx – Server errors (e.g., 500 Internal Server Error)
Versions of HTTP
- HTTP/0.9 – The original version (1991), very simple and limited.
- HTTP/1.0 – Added headers, status codes, and multiple methods.
- HTTP/1.1 – Persistent connections, chunked transfers, caching improvements.
- HTTP/2 – Binary protocol, multiplexing, header compression.
- HTTP/3 – Uses QUIC instead of TCP, improves performance and latency.
HTTP vs HTTPS
While HTTP transmits data in plain text, HTTPS encrypts the data using TLS to ensure privacy, security, and data integrity.
Feature | HTTP | HTTPS |
---|---|---|
Port | 80 | 443 |
Encryption | No | Yes |
Security | Vulnerable to eavesdropping | Secure (TLS/SSL) |
Trust indicator | No lock icon | Lock icon shown in browsers |
Usage | Non-sensitive content | Secure data (login, payment, etc.) |
Use Cases
HTTP is used to:
- Load web pages in browsers
- Send and receive APIs in web applications (via REST)
- Connect web clients and servers
- Fetch dynamic or static content from web servers
Tools and Commands
Example HTTP request with `curl`:
<syntaxhighlight lang="bash"> curl http://example.com </syntaxhighlight>
Inspecting headers:
<syntaxhighlight lang="bash"> curl -I http://example.com </syntaxhighlight>