ℹ️ WHAT IS HTTP?CH.1
1
The Web's Common Tongue

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.

CLIENT-SERVER

Separates concerns — browser (client) asks, web server (server) answers.

HTTP Request Flow: Browser asks → DNS resolves domain → TCP connects → HTTP request sent → Server processes → HTTP response returned → Browser renders
📨 HTTP METHODSCH.2
2
The Action Verbs
GET

Retrieve data from server. Safe and idempotent — never modifies data.

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

Send data to server to create a new resource. Not idempotent.

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

Update an existing resource completely. Idempotent — same result each time.

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

Remove a resource. Idempotent — deleting twice has the same effect.

DELETE /api/users/123 HTTP/1.1
PATCH

Partially update a resource. Only sends changed fields, unlike PUT.

PATCH /api/users/123 HTTP/1.1 {"email": "new@example.com"}
HEAD / OPTIONS

HEAD: Like GET but no body — just headers. OPTIONS: Discover allowed methods.

OPTIONS /api/users HTTP/1.1 → Allow: GET, POST, PUT
📊 HTTP STATUS CODESCH.3
3
The Server's Reply
2xx — SUCCESS
  • 200 OK — Request succeeded
  • 201 Created — Resource created
  • 204 No Content — Success, no body
  • 206 Partial Content — Range response
3xx — REDIRECTION
  • 301 Moved Permanently
  • 302 Found (temporary redirect)
  • 304 Not Modified (use cache)
  • 307 Temporary Redirect
4xx — CLIENT ERROR
  • 400 Bad Request
  • 401 Unauthorized
  • 403 Forbidden
  • 404 Not Found
  • 429 Too Many Requests
5xx — SERVER ERROR
  • 500 Internal Server Error
  • 502 Bad Gateway
  • 503 Service Unavailable
  • 504 Gateway Timeout
📋 COMMON HTTP HEADERSCH.4
4
The Metadata Envelope

HTTP headers carry metadata about the request or response. Sorted by popularity:

HeaderTypeDescriptionExample
Content-TypeResponseMedia type of the resourceapplication/json
User-AgentRequestClient application infoMozilla/5.0...
HostRequestTarget server hostnameexample.com
AcceptRequestAcceptable response typesapplication/json
Cache-ControlBothCaching directivesno-cache
Content-LengthResponseSize of response body1024
AuthorizationRequestAuthentication credentialsBearer token123
Accept-EncodingRequestAcceptable compressiongzip, deflate
Content-EncodingResponseCompression usedgzip
ConnectionBothConnection controlkeep-alive
Set-CookieResponseCookie to set on clientsession=abc123
CookieRequestCookies to send to serversession=abc123
LocationResponseRedirect URLhttps://example.com/new
RefererRequestPrevious page URLhttps://google.com
Accept-LanguageRequestPreferred languagesen-US, en
X-Forwarded-ForRequestClient IP address (proxy)192.168.1.1
ETagResponseResource version identifier"abc123"
If-None-MatchRequestConditional request"abc123"
ServerResponseServer software infonginx/1.18.0
X-Requested-WithRequestAJAX request indicatorXMLHttpRequest
⏳ HTTP VERSIONS EVOLUTIONCH.5
5
The Upgrade Arc
🗂️ HTTP/0.9 (1991) — The Original
Features
  • Only GET method
  • No headers whatsoever
  • 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 added
Example
GET /index.html HTTP/1.0 Host: example.com HTTP/1.0 200 OK Content-Type: text/html
🔗 HTTP/1.1 (1997) — Persistent Connections
Major Improvements
  • Persistent connections (keep-alive)
  • Pipelining support
  • Chunked transfer encoding
  • Host header required
  • PUT, DELETE, OPTIONS methods
Example
GET /page1.html HTTP/1.1 GET /page2.html HTTP/1.1 Connection: keep-alive # Multiple requests on # same connection!
⚡ 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 with HTTP/1.1
🔒 HTTP vs HTTPSCH.6
6
Lock It Down!

HTTP (Port 80)

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

HTTPS (Port 443)

  • ✅ Encrypted with SSL/TLS
  • ✅ Secure data transmission
  • ✅ Certificate validation
  • ⚠️ Slightly slower (encryption overhead)
  • ✅ Required for modern web apps
Always use HTTPS in production! Modern browsers mark HTTP sites as "Not Secure" and search engines penalize unencrypted pages in SEO rankings.