Created
October 31, 2016 15:07
-
-
Save djleonskennedy/93fbf92b9a060524570b9fa5e157b43a to your computer and use it in GitHub Desktop.
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 service = { | |
getUsers: () => fetch(`https://jsonplaceholder.typicode.com/users`), | |
getGroups: () => fetch(`https://jsonplaceholder.typicode.com/posts`) | |
}; | |
async function getData() { | |
try { | |
const peoplePromise = await service.getUsers(); | |
const groupsPromise = await service.getGroups(); | |
const people = await peoplePromise.json(); | |
const groups = await groupsPromise.json(); | |
const data = { people, groups } | |
//or you can return data out of function | |
console.log(`result data`, data) | |
} catch(err) { | |
console.error(err) | |
} | |
} | |
getData(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment