Created
June 22, 2019 20:17
-
-
Save legndery/7dd6c057e0230ebf5a27704ceb4609f0 to your computer and use it in GitHub Desktop.
Promise using Promise.all
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 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