Skip to content

Instantly share code, notes, and snippets.

@MaraAlexa
Created June 21, 2018 09:00
Show Gist options
  • Save MaraAlexa/9639a6fbc314ce713913eccb22a65140 to your computer and use it in GitHub Desktop.
Save MaraAlexa/9639a6fbc314ce713913eccb22a65140 to your computer and use it in GitHub Desktop.
function fetchCatAvatars(userId) {
return fetch(`https://catappapi.herokuapp.com/users/${userId}`)
.then(response => response.json())
.then(user => {
const promises = user.cats.map(catId =>
fetch(`https://catappapi.herokuapp.com/cats/${catId}`)
.then(response => response.json())
.then(catData => catData.imageUrl))
return Promise.all(promises)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment