Request: bodyUsed property
The bodyUsed property indicates whether the body has already been read with one of the four reading methods.
Value
A boolean.
true: the body has been read. Afterward all four reading methods reject withTypeError: Body has already been read, andclone()also throwsTypeError.false: not read yet.- Read-only; assigning to it throws
TypeError. - It becomes
truewhen the body is read and never goes back tofalse. There's no change event: reading is started by your own code. - A
Requestwith no body (aGETrequest, for example) staysfalseafter reading. - Passing a
Requesttofetch()doesn't make ittrue.
Examples
js
async function main() {
const req = new Request('https://httpbin.org/post', { method: 'POST', body: 'hello' });
console.log(await req.text());
console.log(req.bodyUsed);
}
main();Result: Prints hello and true.
Differences from the web
After a Request is passed to fetch(), its bodyUsed becomes true on the web; in Nacre it doesn't change.