Web globals

new Request()

Creates a request description without sending network traffic. Request bodies are consumable streams rather than repeatedly readable strings. Tested on Node.js 22.16.0. Example output (one line per entry): ["POST /books book true"].

Formal Syntax & Structure

nodejs syntaxnodejs
new Request(input[, init])

Parameters & Attributes

NameTypeDescription
inputstring | URL | RequestRequest input.
initobjectMethod, headers and body.

Return Value

Request

Request description.

Working Example

Example Snippetnodejs
const r = new Request('https://example.invalid/books', { method: 'POST', body: 'book' });console.log(r.method, new URL(r.url).pathname, await r.text(), r.bodyUsed);
Node.js Reference