Skip to content

Instantly share code, notes, and snippets.

@djleonskennedy
Created October 31, 2016 15:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djleonskennedy/93fbf92b9a060524570b9fa5e157b43a to your computer and use it in GitHub Desktop.
Save djleonskennedy/93fbf92b9a060524570b9fa5e157b43a to your computer and use it in GitHub Desktop.
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