Description

HTTP (Hypertext Transfer Protocol) is an application-layer protocol used for transmitting hypermedia documents, such as HTML, over the web. It forms the foundation of data communication for the World Wide Web, enabling web browsers and servers to communicate using request-response protocols.

HTTP defines how messages are formatted and transmitted, and what actions web servers and browsers should take in response to various commands. Every time you visit a website, your browser sends HTTP requests to the web server and receives HTTP responses.

Key Characteristics

  • Stateless: Each request is independent; the server does not retain information about previous interactions.
  • Text-based: Human-readable format using plain text.
  • Flexible: Supports multiple content types (HTML, JSON, images, etc.).
  • Extensible: Allows for additional headers and methods.
  • Connectionless (by default): Each connection is established and closed per request, although HTTP/1.1 introduced keep-alive and HTTP/2 multiplexes requests.

HTTP Request Structure

An HTTP request typically includes:

  1. Request Line (method, URL, HTTP version)
  2. Headers (metadata)
  3. Optional Body (for POST/PUT requests)

Example Request:

GET /index.html HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0
Accept: text/html

HTTP Response Structure

An HTTP response consists of:

  1. Status Line (protocol version, status code, reason phrase)
  2. Headers (metadata)
  3. Body (content)

Example Response:

HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 1256

<html>...</html>

HTTP Methods

MethodDescription
GETRetrieve data from server
POSTSubmit data to server
PUTUpdate resource
DELETEDelete specified resource
HEADSame as GET, but without response body
OPTIONSReturns allowed methods for a resource
PATCHPartially update resource

Status Codes

HTTP status codes are grouped into five classes:

Code RangeMeaning
1xxInformational
2xxSuccess
3xxRedirection
4xxClient Error
5xxServer Error

Common Codes:

  • 200 OK – Successful request
  • 301 Moved Permanently – Redirect
  • 400 Bad Request – Malformed request
  • 403 Forbidden – No permission
  • 404 Not Found – Resource not found
  • 500 Internal Server Error – Server malfunction

Headers

Headers allow the client and server to send metadata:

Common Request Headers:

  • Host: Target domain
  • User-Agent: Client software info
  • Accept: Media types supported
  • Authorization: Authentication credentials

Common Response Headers:

  • Content-Type: Format of response
  • Content-Length: Size of response body
  • Set-Cookie: Server-sent cookie
  • Cache-Control: Caching behavior

HTTP Versions

VersionFeatures
HTTP/1.0Basic request/response, no persistent connections
HTTP/1.1Persistent connections, chunked transfer encoding
HTTP/2Binary framing, multiplexing, header compression
HTTP/3Based on QUIC (UDP), improved latency and security

Secure HTTP (HTTPS)

HTTPS is the secure version of HTTP using TLS/SSL encryption. It:

  • Protects data in transit
  • Authenticates the server
  • Prevents tampering and eavesdropping

HTTPS is standard for all modern websites.

HTTP vs HTTPS

FeatureHTTPHTTPS
Port80443
EncryptionNoneTLS/SSL
SecureNoYes
SEO BenefitNoYes

HTTP and REST APIs

HTTP is the foundation for RESTful APIs (Representational State Transfer), where resources are represented by URIs and standard HTTP methods are used for CRUD operations:

  • GET – Read
  • POST – Create
  • PUT – Update
  • DELETE – Delete

Example:

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

Tools for HTTP Debugging

  • Browser Developer Tools (Network tab)
  • Postman – for API testing
  • curl – command-line HTTP client
  • Fiddler / Wireshark – traffic inspection

Summary

HTTP is the backbone of web communication. Understanding how it works—from methods and status codes to headers and versions—empowers developers to build efficient, secure, and scalable web applications. With the rise of REST APIs, microservices, and HTTP/2/3, mastering HTTP is more relevant than ever.