CKTIS / JavaScript
Request — describing a Fetch request
Request represents a request for Fetch. Its constructor prepares the URL, method, headers, and optional body without sending anything. The body is a stream: reading it affects whether it can be reused.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
new Request(input, init?)Request is a Web API from the Fetch Standard, not ECMAScript. new Request(input, init?) sends nothing; pass the request to fetch().
input accepts a URL or another Request; init sets options including method, headers, and body. The default method is GET. A body with GET or HEAD throws TypeError.
text() and json() consume the body. bodyUsed indicates whether the body stream is disturbed, meaning it has been read from or canceled. Canceling an unread body stream also makes bodyUsed true. Call clone() before reading for a separate stream branch; a consumed or locked body prevents cloning.
The example uses no network: it reads the original body and its copy.
Examples
(async () => {
const request = new Request('https://example.org/items', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ id: 7 })
});
const copy = request.clone();
console.log(request.method);
console.log(request.headers.get('content-type'));
console.log(request.bodyUsed);
console.log(await request.text());
console.log(request.bodyUsed);
console.log(await copy.text());
})().catch(console.error);Result
POST
application/json
false
{"id":7}
true
{"id":7}The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.