I want to get some results back from a REST API that supports pagination. The way the API works is you make the initial request and get back the following.
- List of objects
- Total Count
- Number Remaining
- Result Identifier
To get the remaining object I need to make another request passing in the results identifier and rinse and repeat.
What I am having trouble with is writing a method that does this "elegantly". I would like to have a single method where I pass in the initial query and it makes as many API calls as necessary to get back all objects and just adds them together as a single list which is returned from the method.
Are there any good design patterns to follow in this type of scenario? Do I need to use recursion for the method to call itself or is there a simpler approach? I see lots of posts on how to design an API to properly paginate but have not found anything that describes how to properly consume an API that supports pagination.
Aucun commentaire:
Enregistrer un commentaire