Created
October 16, 2016 03:03
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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