When requesting Q&As from stackexchange API, the JSON response has a has_more (Boolean) argument and when it is true that means there are more requests possible with
http://api.stackexchange.com/2.2/questions?order=desc&sort=activity&site=stackoverflow&filter=withbody&pagesize=30&tagged=java&page=1
the response looks like this
{items: [
..]
has_more: true,
quota_max: 300,
quota_remaining: 281
}
I want the best way to get all possible responses fetched while maintaining the quota_max limit. So far, my module is able to get one result :
exports.getQuestions = function(q,tag,page){
return new Promise(function(resolve, reject){
var request = require('request');
var url = 'http://api.stackexchange.com/2.2/search?order=desc&sort=votes&site=stackoverflow&filter=withbody&pagesize=30';
url = url + '&q=' + q + '&tagged='+ tag + "&page="+page;
request({headers: {
'Accept': 'application/json; charset=utf-8',
'User-Agent': 'RandomHeader'
},
uri: url,
method: 'GET',
gzip: true
},
function(err, res, body) {
if (err || res.statusCode !=200){
reject (err || {statusCode: res.statusCode});
}
resolve(body);
});
})}
But I want to loop through or make multiple calls in a proper way. Any help is appreciated.