Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Share On Stumbleupon
Contact us
Hide Buttons

Parse html response with fetch API

We will learn how to read the html response returned from REST API end point which was called using the new fetch API.

The Fetch API pro­vides an inter­face for fetch­ing resources (includ­ing across the network).

If you have a REST API end point, which returns you the html response, then you can use the response.text() method to parse the html as shown below.

return fetch(url).then(function(res) {
    return res.text();
}).then(function(html) {
    console.log(`html = ${html}`);
});

response.text() takes a response stream and reads it to com­ple­tion. It returns a promise that resolves with a text.

Fur­ther reading :


You may also like...