Skip to main content
The three objects shared by fetch and http.serve:
  • Request — an outbound request (or the inbound one, in a handler)
  • Response — what you return from a handler or get from fetch
  • Headers — a case-insensitive header collection

Response

Constructor

Properties

Body readers

Readers do not consume — call any reader any number of times, in any order:
clone() corrupts instead of teeing — observed verbatim:

Statics

In an HTTP handler

Response.error() builds a network-error-shaped response (status: 0, type: "error"). The WebSocket upgrade is automatic and never passes through your handler — there is no { status: 101 } return (see WebSocket).

Request

Constructor

Properties

Methods

text(), json(), arrayBuffer(), blob(), formData(), bytes(), clone() — same contract as Response. Plus:

Headers

Names are case-insensitive; iteration order is insertion order.

Iterating

Headers itself is not iterable — iterate the arrays entries() returns:

Gotchas

  • bodyUsed never flips — it stays false before, during, and after every read. Don’t branch on it; bodies are simply re-readable.
  • Status code range (100–999) — status is bounded to valid 3-digit HTTP status codes. Out-of-range numbers (negative, < 100, or > 999) fall back to default (200, or 302 for Response.redirect).
  • headers.size is a function — h.size is undefined; h.size() is the number. Same for URLSearchParams.size.
  • clone() corrupts the copy ("OKABCDEFGH" → "OKOKABCDEF") — re-read the original instead of cloning.
  • new Response(body) copies the bytes; mutating the original afterwards does not change the response.
  • Response.redirect(url) without a URL throws — and with one it still sends no Location header, so clients never follow it.
  • In a handler, the third argument (body) is already a string — you don’t call .text() on it.

See also