Search...
text( )
Reads the response body as a string.
Description
The text()
function reads the body response stream to its completion and
formats the data as a string. It returns a Promise that resolves to the
response body as a string.
Syntax
function text(): Promise<string>
text Parameters
This function does not take any parameters.
Returns
Fulfilled - The response body as a string. Rejected - The errors that caused the rejection.
Return Type:
Promise<string>
Was this helpful?
Get the response's body as text.
Copy Code
1let text = httpResponse.text(); // {"key": "some value"}
Get the response's body as text and log it to the console.
Copy Code
1fetch(url, {method: 'get'})2 .then(httpResponse => httpResponse.text())3 .then(text => console.log(text));