Request.text()
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.
Syntax
request.text().then(function (text) {
// do something with the text sent in the request
});
Parameters
None.
Return value
A Promise that resolves with a String
.
Examples
const text = "Hello world";
const request = new Request('/myEndpoint', {
method: 'POST',
body: text
});
request.text().then(function(text) {
// do something with the text sent in the request
});
Specifications
Specification |
---|
Fetch Standard # ref-for-dom-body-text① |
Browser compatibility
BCD tables only load in the browser