Contents

Web & Networking › HTTP

HTTP Request

A method, URL, headers and an optional body.

Also known as: HTTP request message, request line, request headers

An HTTP request is the message a client sends to a server. It has four parts.

POST /orders?source=web HTTP/1.1
Host: api.example.com
Content-Type: application/json
Authorization: Bearer eyJhbGciOi...
Accept: application/json

{"item_id": 7, "quantity": 2}
PartExampleMeaning
Request linePOST /orders?source=web HTTP/1.1the method, the path and query, and the protocol version
HeadersHost, Content-Type, Authorizationmetadata about the request (headers)
Blank lineseparates headers from the body
Body (optional){"item_id": 7 ...}data being sent (body)

The full address comes from the Host header plus the path (and the scheme and port you connected with) (URLs).

What each part is for

  • Method: what to do (GET read, POST create…).
  • Path: which resource (/orders/917).
  • Query string: optional parameters, such as filters and paging (query strings).
  • Headers: who you are, what you send and accept, caching hints, cookies.
  • Body: the payload for POST, PUT and PATCH.

Seeing real requests

curl -v https://example.com          # shows the request it sends

The network tab in browser DevTools lists every request, with headers and bodies.

Points to remember

  • A GET normally has no body.
  • Header names are case-insensitive.
  • Cookies travel in the Cookie header.
  • Everything in a request is controlled by the client, so the server must validate it (never trust the client).
  • HTTP/2 and HTTP/3 carry the same information in a binary form.

The reply is an HTTP response.