跳到主要内容

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

MethodPurposeIdempotentSafe
GETRetrieve data
POSTCreate resource
PUTUpdate/replace
DELETEDelete resource
PATCHPartial 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 RangeMeaning
2xxSuccess
3xxRedirection
4xxClient error
5xxServer error

Common codes:

  • 200 OK
  • 201 Created
  • 400 Bad Request
  • 401 Unauthorized
  • 404 Not Found
  • 500 Internal Server Error

HTTP Headers

Metadata about request/response

Common headers:

  • Content-Type: MIME type
  • Authorization: Authentication
  • Cache-Control: Caching directives
  • Accept: What client accepts
  • User-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