Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.