Response object returned by the
fetch() method contains the information about the request and the response of the network request including headers, status code, and status message.
Response object provides several methods to access the response body like
text(), and more. To get a response as an HTML string, you can use the
Here is an example that downloads the Google homepage as an HTML string and prints it on the console:
fetch('https://www.google.com') .then(res => res.text()) .then(res => console.log(res)) .catch(err => console.error(err));
text() method returns the response body as a string. Take a look at this section to learn more about Fetch API response formats.
👋 If you enjoy reading my articles and want to support me to continue creating free tutorials, ☕ Buy me a coffee (cost $5) .
Need help to launch a new product? I am available for contract work. Hire me to accomplish your business goals with engineering and design.