Created
June 22, 2019 20:10
-
-
Save legndery/67810c8ac42fa9c0611613a33be25806 to your computer and use it in GitHub Desktop.
Callback Using request module
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 request = require('request'); | |
const empIds = ['72632', '72633', '72634']; | |
const dummyRESTurl = 'http://dummy.restapiexample.com/api/v1/employee/'; | |
const result = []; | |
let count = 0; | |
empIds.forEach((empID, i)=>{ | |
request(`${dummyRESTurl}${empID}`, (err, resp, body)=>{ | |
result.push(JSON.parse(body)); | |
count++; | |
if(count === empIds.length){ | |
render(); | |
} | |
}) | |
}) | |
function render(){ | |
//does something with the collective data | |
console.log(result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment