Be the first user to complete this post

  • 0
Add to List

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 provides an interface for fetching resources (including 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 completion. It returns a promise that resolves with a text. Further reading :

Also Read:

  1. Default function parameters
  2. imperative vs declarative/functional programming
  3. Testing promise sequence using mocha, chai, chai-as-promised, sinon
  4. Split a string in javascript when both comma and spaces are present
  5. css - circular profile pictures
  6. gzip compress and cache api response in express
  7. Progressive enhancement vs Graceful degradation
  8. Getting started with localStorage vs sessionStorage in html5