Skip to content

Instantly share code, notes, and snippets.

@bbachi
Created March 11, 2023 04:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbachi/5bd39720e636357ea86639bb13b6eb36 to your computer and use it in GitHub Desktop.
Save bbachi/5bd39720e636357ea86639bb13b6eb36 to your computer and use it in GitHub Desktop.
Sequential Calls
const axios = require('axios');
async function getUsers() {
return await axios.get('/api/users');
}
async function getContacts() {
return await axios.get('/api/contacts');
}
async function getAddresses() {
return await axios.get('/api/addresses');
}
export async function getUserInfo() {
try{
const users = await getUsers();
const contacts = await getContacts();
const addresses = await getAddresses();
const result = [];
users.data.map((user) => {
result.push({
...user,
...contacts.data.find((contact) => contact.userId === user.userId),
...addresses.data.find((address) => address.userId === address.userId)})
});
console.log(result)
return result;
}catch(error) {
return [];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment