Skip to content

Instantly share code, notes, and snippets.

@tzvc
Created February 23, 2018 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tzvc/26e2fca5550ea2fa35fa49f926a08c88 to your computer and use it in GitHub Desktop.
Save tzvc/26e2fca5550ea2fa35fa49f926a08c88 to your computer and use it in GitHub Desktop.
Enrich data using ES2016 async/await
async function get(type) {
const rottentomatoesResponse = await fetch(`https://www.rottentomatoes.com/api/private/v2.0/browse?sortBy=popularity&type=${type}`)
const json = await rottentomatoesResponse.json()
const titles = json.results.map(element => {
return {
url: element.url,
title: element.title.split(':')[0]
}
});
return await Promise.all(titles.map(title => getImageFrom(title)))
}
async function getImageFrom({ title }) {
const tvmazeResponse = await fetch(`http://api.tvmaze.com/singlesearch/shows?q=${title}`)
const json = await tvmazeResponse.json()
return {
img: json.image,
title
}
}
get("new").then(resp => {console.log("enriched data", resp)})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment