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
HostandContent-Type. - An empty line: this marks the end of the headers.
- Body: here, a JSON document. The
Content-Lengthheader gives its size.
The response has the same shape:
- Status line: the version, the status code
201, and the reason phraseCreated. - Headers: these include
Location, which points to the new resource, andContent-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.
Read more
- HTTP messages (MDN) (https://developer.mozilla.org/en-US/docs/Web/HTTP/Messages)developer.mozilla.org