Skip to content

Instantly share code, notes, and snippets.

@legndery
Created June 22, 2019 20:17
Show Gist options
  • Save legndery/7dd6c057e0230ebf5a27704ceb4609f0 to your computer and use it in GitHub Desktop.
Save legndery/7dd6c057e0230ebf5a27704ceb4609f0 to your computer and use it in GitHub Desktop.
Promise using Promise.all
const axios = require('axios');
const empIds = ['72632', '72633', '72634'];
const dummyRESTurl = 'http://dummy.restapiexample.com/api/v1/employee/';
let promises = [];
empIds.forEach((empID, i)=>{
promises.push(axios.get(`${dummyRESTurl}${empID}`));
})
Promise.all(promises)
.then((result)=>{
//do something with data
console.log(result.map(r=>r.data));//because axios returns full response
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment