Note: This feature is available in Web Workers.
The text() method of the Request interface reads the request body and returns it as a promise that resolves with a String. The response is always decoded using UTF-8.
text()None.
A Promise that resolves with a String.
TypeErrorThrown for one of the following reasons:
Content-Encoding header is incorrect).const text = "Hello world";
const request = new Request("/myEndpoint", {
method: "POST",
body: text,
});
request.text().then((text) => {
// do something with the text sent in the request
});