What is HTTP

Version Features
HTTP/1.1 Keep-Alive, header-based multiplexing
HTTP/2 Binary protocol, multiplexing, server push
HTTP/3 Built on QUIC, low-latency, encrypted by default
Feature HTTP HTTPS
Security Unencrypted Encrypted via TLS/SSL
Port 80 443
Data Protection None Prevents MITM & sniffing

HTTP Headers

Header Purpose Used In Example
Content-Type Specifies media type Both application/json
Authorization Auth token for protected routes Request Bearer token123
Accept Desired response format Request application/json
User-Agent Client information Request Mozilla/5.0
Cache-Control Caching behavior Both no-cache, max-age=3600
Set-Cookie Sends cookie to client Response Set-Cookie: session=abc123
Content-Length Indicates body size in bytes Response Content-Length: 128

Content-Type & MIME Types

Content Type MIME Example
JSON application/json
HTML text/html
PNG Image image/png
PDF application/pdf

HTTP Request

GET /api/users HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0
Accept: application/json

---

POST /api/users HTTP/1.1
Host: example.com
Content-Type: application/json
Content-Length: 43

{
  "name": "John",
  "email": "[email protected]"
}
Component Description
Method GET, POST, PUT, DELETE, etc.
URL Target endpoint, e.g., /api/users
HTTP Version e.g., HTTP/1.1, HTTP/2, HTTP/3
Headers Metadata about the request
Body Present in methods like POST, PUT

HTTP Response

HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 123

{
  "id": 1,
  "name": "John Doe"
}
Component Description
Status Code Result of the request, e.g., 200 OK
Headers Metadata about the response
Body Optional data returned from the server

Caching Mechanisms

Strong Caching