Skip to content

Instantly share code, notes, and snippets.

@bwll
Last active May 22, 2017 18:12
Show Gist options
  • Save bwll/81548abf90b4bdb550ac1c234dd2b23c to your computer and use it in GitHub Desktop.
Save bwll/81548abf90b4bdb550ac1c234dd2b23c to your computer and use it in GitHub Desktop.
/*
* Fetch API
* https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
*/
const uri = 'https://api.spotify.com/v1/albums/21KIagsx1ZvYcv0sVkEAWv/tracks';
const req = new Request(uri, {
method: 'get',
headers: new Headers({
'content-type':'application/json'
})
});
fetch(req)
.then(res => {
if(res.ok) {
return res.json()
} else {
return Promise.reject({
status: res.status,
statusText: res.statusText
})
}
})
.then(data => {
const obj = data.items;
obj.forEach(function(i) {
console.log(i);
});
})
.catch(err => {
console.log(err.statusText);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment