Contents

Web & Networking › HTTP

HTTP Response

A status code, headers and a body.

Also known as: HTTP response message, status line, response headers

An HTTP response is the message a server sends back after a request. It has three parts.

HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
Set-Cookie: session=abc123; HttpOnly

{"id": 917, "status": "paid"}
PartExampleMeaning
Status lineHTTP/1.1 200 OKthe protocol, a status code and a short reason
HeadersContent-Type, Set-Cookiemetadata about the response (headers)
Body (optional){"id": 917 ...}the content: HTML, JSON, an image (body)

Reading one

  1. Status code first: did it work? The first digit says the class: 2xx success, 3xx redirect, 4xx client error, 5xx server error (status codes).
  2. Content-Type: how to interpret the body (Content-Type).
  3. Other headers: caching rules (HTTP caching), cookies to store, redirects (Location), CORS permissions (CORS).
  4. The body: the actual data, or an error description.
const res = await fetch("/api/orders/917");
res.status;                 // 200
res.headers.get("content-type");
const data = await res.json();

Remember: fetch doesn’t throw on a 404 or 500. Check res.ok (fetch API).

Writing good ones

  • Use the right status code, not 200 for everything.
  • Always set Content-Type.
  • Send consistent error bodies (error response format).
  • Set caching headers deliberately.
  • Don’t leak internals: server versions, stack traces, internal IPs.
  • Add security headers (security headers).

Responses answer an HTTP request. You can inspect them in the network tab or with curl -i.