HTTP
HTTP = protocol for web communication
What is HTTP?
"HyperText Transfer Protocol"
HTTP is the protocol used for:
- Communication between client and server
- Request-response model
- Stateless protocol
- Foundation of the web
"HTTP is a stateless request-response protocol used for communication between web browsers and servers."
HTTP Methods
GET · POST · PUT · DELETE · PATCH
| Method | Purpose | Idempotent | Safe |
|---|---|---|---|
| GET | Retrieve data | ✅ | ✅ |
| POST | Create resource | ❌ | ❌ |
| PUT | Update/replace | ✅ | ❌ |
| DELETE | Delete resource | ✅ | ❌ |
| PATCH | Partial update | ❌ | ❌ |
"HTTP methods define the action to be performed, with GET being safe and idempotent, while POST creates new resources."
HTTP Status Codes
2xx success, 4xx client error, 5xx server error
| Code Range | Meaning |
|---|---|
| 2xx | Success |
| 3xx | Redirection |
| 4xx | Client error |
| 5xx | Server error |
Common codes:
200OK201Created400Bad Request401Unauthorized404Not Found500Internal Server Error
HTTP Headers
Metadata about request/response
Common headers:
Content-Type: MIME typeAuthorization: AuthenticationCache-Control: Caching directivesAccept: What client acceptsUser-Agent: Client identifier
"HTTP headers provide metadata about requests and responses, controlling caching, authentication, and content negotiation."
Request Structure
Method + URL + Headers + Body
GET /api/users HTTP/1.1
Host: example.com
Accept: application/json
"HTTP requests consist of a method, URL, headers, and optional body."
Response Structure
Status + Headers + Body
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 123
{"data": "..."}
Stateless Nature
Each request is independent
- No memory between requests
- Each request contains all needed info
- Cookies/sessions add state
"HTTP is stateless, meaning each request is independent, though cookies and sessions can add state."
HTTPS
HTTP + TLS encryption
- Encrypted communication
- Data integrity
- Authentication
- Required for sensitive data
"HTTPS adds TLS encryption to HTTP, securing data in transit."
9️⃣ HTTP/2 and HTTP/3
Faster, multiplexed, binary
- HTTP/2: Multiplexing, header compression
- HTTP/3: QUIC protocol, faster connections
"HTTP/2 and HTTP/3 improve performance with multiplexing, header compression, and better connection handling."
"HTTP is a stateless request-response protocol for web communication. It uses methods like GET, POST, PUT, DELETE, status codes (2xx success, 4xx client errors, 5xx server errors), and headers for metadata. HTTPS adds encryption, and HTTP/2/3 improve performance with multiplexing and compression."
🧠 Ultra-Short Cheat Sheet
Request-response protocol
Stateless
Methods (GET/POST/PUT/DELETE)
Status codes (2xx/4xx/5xx)
Headers (metadata)
HTTPS = encrypted
HTTP/2 = multiplexing