CKTIS / JavaScript
Response.text() — reading a body as text
Response.text() reads the entire response body and returns a Promise containing text decoded as UTF-8.
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
response.text() // Promise<string>response.text() returns a Promise<string> that fulfills after the entire body has been read. It decodes bytes as UTF-8 regardless of the Content-Type charset. It does not parse JSON.
If response.body is null, every call fulfills with an empty string and bodyUsed stays false. If there is a body stream, reading it sets bodyUsed to true, even if the stream contains zero bytes. If the stream is already disturbed (reading has started or the stream has been canceled) or locked, the promise rejects with TypeError. To read a streamed body twice, call response.clone() before the first read.
The method buffers the entire body, so consider memory usage. It does not check response.ok. This is a Web API defined by the Fetch Standard, not an ECMAScript feature.
Examples
(async () => {
const response = new Response("Cześć!", {
headers: { "Content-Type": "text/plain; charset=utf-8" }
});
console.log(await response.text());
console.log(response.bodyUsed);
})().catch(console.error);Result
Cześć! true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.