I'm trying to understand promises so I tried a simple get request on twitch. What I don't understand is why does json()
returns a promise. Why ? The response already has the data in it so why the hell is it a promise ?
fetch('https://api.twitch.tv/kraken/games/top?limit=10&offset=0')
.then( resp => {
resp.json()
.then(function(data) {
console.log(data);
});
});
In other words : The first then
, I understand, it waits for the response. However when entering the then function it means that the response has been received thus the data should be immediately accessible without the need of yet another promise. It just confuses me.