I have a REST API on my server on which I need to make multiple calls with mobile number as argument. I read these mobile numbers from a database. Internet connection is unreliable on client side so I want to make just one request to my server. Is there any npm module I can use to do this? That is combine all request as one batch and send it to server. I thought of sending all mobiles as json or csv but the problem is it is an authenticated request using superagent as follows:
async.waterfall([
function one(callback) {
agent1
.post(login-url)
.type('form') // send request in form format
.send({
username: username,
password: password
})
.end(function(err, res) {
console.log("response for login is ", res.statusCode);
callback();
});
},
function two(callback) {
for (var i = 0; i < count; i++) {
console.log("i is ", i);
if (validatePayment(rows[i].Payment) == true && validateMobile(rows[i].Mobile) == true && i!=0) {
console.log(rows[i].CustomerID,rows[i].Payment,rows[i].Mobile,rows[i].Email);
agent1
.post(checkin-url)
.send({
phone: rows[i].Mobile,
outlet: outletid
})
.end(function(err, res) {
//console.log(i);
log.info("response for checkins is ", res.statusCode, "for customerid ");
console.log("response for checkins is ", res.statusCode, "for customerid ");
callback();
});
}
else{
log.info("validation failed for CustomerID");
console.log("validation failed for CustomerID ");
}
}
}],
function(err, results) {
//console.log(results);
}
);
So as you can see If I have 100 mobile numbers, I am making 100 calls to check-url. I just want to make one and then handle it on server. How to proceed for this problem?