I'm using a NodeJS module called node-github, which is a wrapper around the Github API, to get some statistics about certain users, such as their followers:
var getFollowers = function(user, callback) {
github.user.getFollowers(user, function(err, res) {
console.log("getFollowers", res.length);
callback(err, res);
});
};
...
getFollwers({user: mike}, function(err, followers) {
if(err) {
console.log(err);
}
else {
console.log(followers);
}
});
Apparently, Github limits call results to a maximum of 100 (via the per_page
parameter), and utilizes the Link header to let you know a 'next page' of results exists.
The module I'm using provides several easy methods to handle the Link header, so you won't need to parse it. Basically, you can call github.hasNextPage(res)
or github.getNextPage(res)
(where res
is the response you received from the original github.user.getFollowers()
call)
What I'm looking for is the right approach/paradigm to having my function return all results, comprised of all pages. I dabbled a bit with a recursive function, and though it works, I can't help but feeling there may be a better approach.
This answer could serve as a good approach to handling all future Link header calls - not just Github's - if the standard catches on.
Thanks!