Last active
May 22, 2017 18:12
-
-
Save bwll/81548abf90b4bdb550ac1c234dd2b23c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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