Last active
January 4, 2018 16:44
-
-
Save isabellachen/39be0aa1478e26c8f70fbd40859cb68a to your computer and use it in GitHub Desktop.
Use Promise All to return an array of values derived from a fetch call to an API
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
const fetchFromGithub = async (endpoint) => { | |
const url = `https://api.github.com/users/${endpoint}` | |
const response = await fetch(url) | |
return await response.json() | |
} | |
const getGithubUserInfo = async (handle) => { | |
return await Promise.all([ | |
fetchFromGithub(handle), | |
fetchFromGithub(`${handle}/repos`) | |
]) | |
} | |
getGithubUserInfo('isabellachen').then(data => { | |
console.log(data) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment