HTTP Protocol Guide

Hypertext Transfer Protocol - Web Communication Standard

What is HTTP?

HTTP (Hypertext Transfer Protocol) is an application-layer protocol for distributed, collaborative, hypermedia information systems. It's the foundation of data communication for the World Wide Web.

Stateless

Each request is independent and doesn't retain information about previous requests.

Request/Response

Client sends requests, server responds with data or status information.

Text-based

Human-readable protocol that's easy to debug and understand.

HTTP Request/Response Flow

HTTP Methods

GET

Retrieve data from server

GET /api/users HTTP/1.1 Host: example.com

POST

Send data to server

POST /api/users HTTP/1.1 Content-Type: application/json {"name": "John"}

PUT

Update existing resource

PUT /api/users/123 HTTP/1.1 Content-Type: application/json {"name": "Jane"}

DELETE

Remove resource

DELETE /api/users/123 HTTP/1.1

HTTP Status Codes

2xx Success

  • 200 OK
  • 201 Created
  • 204 No Content

3xx Redirection

  • 301 Moved Permanently
  • 302 Found
  • 304 Not Modified

4xx Client Error

  • 400 Bad Request
  • 401 Unauthorized
  • 404 Not Found

5xx Server Error

  • 500 Internal Server Error
  • 502 Bad Gateway
  • 503 Service Unavailable

Common HTTP Headers (Sorted by Popularity)

Header Type Description Example
Content-Type Response Media type of the resource application/json
User-Agent Request Client application info Mozilla/5.0...
Host Request Target server hostname example.com
Accept Request Acceptable response types application/json
Cache-Control Both Caching directives no-cache
Content-Length Response Size of response body 1024
Authorization Request Authentication credentials Bearer token123
Accept-Encoding Request Acceptable compression gzip, deflate
Content-Encoding Response Compression used gzip
Connection Both Connection control keep-alive
Set-Cookie Response Cookie to set session=abc123
Cookie Request Cookies to send session=abc123
Location Response Redirect URL https://example.com/new
Referer Request Previous page URL https://google.com
Accept-Language Request Preferred languages en-US, en
X-Forwarded-For Request Client IP address 192.168.1.1
ETag Response Resource version identifier "abc123"
If-None-Match Request Conditional request "abc123"
Server Response Server software info nginx/1.18.0
X-Requested-With Request AJAX request indicator XMLHttpRequest

HTTP Versions Evolution

HTTP has evolved through several versions, each bringing new features and improvements to web communication.

HTTP/0.9 (1991) - The Original

Features
  • • Only GET method
  • • No headers
  • • HTML only responses
  • • Connection closes after response
Example
Request:
GET /index.html
Response:
<html>...</html>

HTTP/1.0 (1996) - Headers & Status Codes

New Features
  • • HTTP headers introduced
  • • Status codes (200, 404, etc.)
  • • Content-Type support
  • • POST, HEAD methods
Example
Request:
GET /index.html HTTP/1.0
Host: example.com
Response:
HTTP/1.0 200 OK
Content-Type: text/html

HTTP/1.1 (1997) - Persistent Connections

Major Improvements
  • • Persistent connections
  • • Pipelining support
  • • Chunked transfer encoding
  • • Host header required
  • • PUT, DELETE, OPTIONS methods
Example
Multiple requests on same connection:
GET /page1.html HTTP/1.1
GET /page2.html HTTP/1.1
Connection: keep-alive

HTTP/2 (2015) - Multiplexing & Binary

Revolutionary Features
  • • Binary protocol (not text)
  • • Multiplexing (multiple streams)
  • • Server push capability
  • • Header compression (HPACK)
  • • Stream prioritization
Benefits
  • • Faster page loading
  • • Reduced latency
  • • Better resource utilization
  • • Backward compatible

HTTP vs HTTPS

HTTP (Port 80)

  • • Unencrypted communication
  • • Faster performance
  • • No SSL/TLS overhead
  • • Vulnerable to attacks
  • • Data can be intercepted

HTTPS (Port 443)

  • • Encrypted with SSL/TLS
  • • Secure data transmission
  • • Certificate validation
  • • Slightly slower due to encryption
  • • Required for modern web apps