HTTP request and response structure explained
request line, response status line, HTTP headers, message body, CRLF, Content-Type, Content-Length, Host header
Anatomy of an HTTP Message
HTTP is a text protocol. Every request and response is a structured text message with three parts: a start line, headers, and an optional body separated by a blank line.
HTTP Request
GET /api/users HTTP/1.1
Host: api.example.com
Accept: application/json
Authorization: Bearer eyJhbGc...
The first line is the request line: method + path + HTTP version. Headers follow as Name: Value pairs, each ending in CRLF (
). A blank line (double CRLF) signals the end of headers. The body follows — absent for GET requests.
HTTP Response
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 42
{"id": 1, "name": "Alice"}The first line is the status line: HTTP version + status code + reason phrase. Headers follow, then a blank line, then the optional body.
Required headers
HTTP/1.1 mandates the Host header on every request — without it, virtual hosting fails because one server IP may serve dozens of domains. The server uses Host to route to the correct application. When a body is present, either Content-Length or Transfer-Encoding: chunked is required so the receiver knows where the message ends and the next one begins.
# See raw HTTP with curl
curl -v https://httpbin.org/get 2>&1 | head -30