Skip to content Skip to sidebar Skip to footer

How To Access Data From "passthrough" Object Returned After Api Call?

I am sending a fetch request with node-fetch to the following url: http://fantasy.premierleague.com/api/bootstrap-static/ in order to get back some JSON-data. Accessing the URL in

Solution 1:

Fetch returns a response stream as mentioned here in the answer to a similar question You can read data in chunks and add the chunk to array and then do whatever you need to do with that data. A simpler approach would be to use npm request package. Here's an example.

const request = require('request');
let options = {json: true};

const url = 'http://fantasy.premierleague.com/api/bootstrap-static/'
request(url, options, (error, res, body) => {
    if (error) {
        return  console.log(error)
    };

    if (!error && res.statusCode == 200) {
        console.log(body);
        // do something with JSON, using the 'body' variable
    };
});

Post a Comment for "How To Access Data From "passthrough" Object Returned After Api Call?"