HTTP is the protocol that powers the web. Every time you load a webpage, submit a form, or call an API, your browser sends an HTTP request to a server and receives an HTTP response. It defines the format of messages between clients and servers.

How HTTP Works

HTTP is a request-response protocol. The client sends a request with a method (GET, POST, PUT, DELETE), URL, headers, and optional body. The server responds with a status code (200, 404, 500), headers, and a body (HTML, JSON, images).

HTTP/1.1 was the standard for 15 years. HTTP/2 (2015) added multiplexing and header compression. HTTP/3 (2022) replaced TCP with QUIC for faster connections. Modern browsers use HTTP/2 or HTTP/3 automatically.

Every HTTP request includes headers — key-value pairs carrying metadata. Content-Type tells the server what format the body is in. Authorization carries auth tokens. Cache-Control manages caching behavior.

Why Developers Use HTTP

Understanding HTTP is non-negotiable for web developers. Every API call, form submission, file upload, and page load uses HTTP. Debugging tools like browser DevTools Network tab, curl, and Postman all work at the HTTP level.

Key Concepts

  • Request Methods — GET retrieves data, POST sends data, PUT updates, DELETE removes, PATCH partially updates
  • Status Codes — 1xx informational, 2xx success, 3xx redirect, 4xx client error, 5xx server error
  • Headers — Key-value pairs in requests and responses carrying metadata — Content-Type, Authorization, Cache-Control
  • Request Body — Data sent with POST/PUT requests — form data or JSON for API calls
  • Cookies — Small data pieces the server sends to the browser, which sends them back with every subsequent request
  • HTTPS — HTTP encrypted with TLS — the secure version. Every production site should use HTTPS.

HTTP Request with curl

bash
# GET request with headers
curl -H "Authorization: Bearer token123" \
     https://api.example.com/users

# POST request with JSON body
curl -X POST \
     -H "Content-Type: application/json" \
     -d '{"name": "Alice", "email": "alice@dev.com"}' \
     https://api.example.com/users

Frequently Asked Questions

What is the difference between HTTP and HTTPS?

HTTPS is HTTP encrypted with TLS/SSL. The data is encrypted in transit so attackers can't read it. HTTPS is required for any site handling passwords, payments, or personal data — and Google ranks HTTPS sites higher.

What HTTP method should I use?

GET for reading data (idempotent, cacheable). POST for creating data or submitting forms. PUT for full updates. PATCH for partial updates. DELETE for removal.

What is HTTP/3?

HTTP/3 replaces TCP with QUIC, a UDP-based protocol that eliminates head-of-line blocking and reduces connection setup time. Most modern browsers and CDNs support it.