CodePark/ questions / How a request travels
START PRACTICINGPRACTICE
Backend question · HTTP & API design › How a request travels

Name the parts of this HTTP/1.1 request and response.

POST /orders HTTP/1.1
Host: api.shop.com
Content-Type: application/json
Content-Length: 27

{"sku":"A-1","quantity":2}

HTTP/1.1 201 Created
Location: /orders/981
Content-Type: application/json

{"id":981,"status":"pending"}

The request has these parts, in order:

  • Request line: the method POST, the request target /orders, and the protocol version.
  • Header fields: one per line, such as Host and Content-Type.
  • An empty line: this marks the end of the headers.
  • Body: here, a JSON document. The Content-Length header gives its size.

The response has the same shape:

  • Status line: the version, the status code 201, and the reason phrase Created.
  • Headers: these include Location, which points to the new resource, and Content-Type.
  • An empty line, then the response body.

HTTP/2 and HTTP/3 carry the same meaning in binary frames (small binary pieces of data). They split the start line into pseudo-headers like :method and :path. But the model is the same: method, target, status, headers and body.

  • The request line holds the method, the target and the version.
  • The status line holds the version, the status code and the reason phrase.
  • Headers come first, then a blank line, then an optional body.
  • HTTP/2 and HTTP/3 keep the same meaning but send it in binary frames.