How HTTP request-response cycle works
HTTP protocol, request structure, response structure, status codes, headers, stateless communication
The HTTP Request-Response Cycle
Every API call is an HTTP transaction. The client sends a request; the server sends back a response. That's it. Understanding this cycle is the foundation of everything else.
Anatomy of an HTTP Request
A request has four parts: method (GET, POST, PUT, DELETE), URL (the resource address), headers (metadata like Content-Type), and an optional body (data payload for POST/PUT).
GET /users/42 HTTP/1.1
Host: api.example.com
Authorization: Bearer eyJhbGci...
Accept: application/jsonAnatomy of an HTTP Response
The server replies with a status code, headers, and a body. Status codes are grouped by first digit: 2xx success, 3xx redirect, 4xx client error, 5xx server error.
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": 42,
"name": "Alice"
}HTTP is stateless β each request is independent. The server stores no memory of previous requests unless you explicitly pass context (a token, session ID, etc.) in every request. This constraint is intentional and scales well.
