Created
February 23, 2018 15:13
-
-
Save tzvc/26e2fca5550ea2fa35fa49f926a08c88 to your computer and use it in GitHub Desktop.
Enrich data using ES2016 async/await
This file contains hidden or 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
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