Skip to content

Instantly share code, notes, and snippets.

@lancegliser
Created October 16, 2016 03:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lancegliser/92c0ba5088f4bcda633b0aa8eea33b7c to your computer and use it in GitHub Desktop.
Save lancegliser/92c0ba5088f4bcda633b0aa8eea33b7c to your computer and use it in GitHub Desktop.
Pulls down a full paged api using promises and recursive functions. Mostly written against Angular's $http
function getAllPagedData(url){
var data = [];
var page = 1;
return _getPage(page);
function _getPage(page){
return $http.get(url, {params: {format: 'json', page: page}})
.then(function(result){
data = data.concat(result.results);
if( result.next ){
page++;
return _getPage(page);
}
return data;
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment