Axios multiple calls, one promise
const axios = require('axios')
const checkMultipleAddresses = (addresses) => {
return Promise.all(
addresses.map((address, index) => {
return new Promise((resolve, reject) => {
axios.get('https://bithomp.com/api/v1/userinfo/' + address).then(result => {
resolve(Object.assign(result.data, { __index: index }))
}).catch(e => {
// Got an Error from the HTTP call, but we handle it as OK (resolve instead of reject)
resolve({ address: address, error: true, message: e.toString(), __index: index })
})
})
})
)
}
checkMultipleAddresses([
'rDpsdD9vTwkf1GiNkxunLLDBXsEXG9GNmk',
'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
'rPEPPER7kfTD9w2To4CQk6UCfuHM9c6GDY'
]).then(results => {
results.sort((a, b) => { return a.__index - b.__index })
console.log('Multiple addresses result:', results)
})
no comments