'Best practice to retrieve multiple pages from API?

I am working on a Springboot microservice that interacts with a 3rd-party API. The API returns a paged response but I will have to retrieve multiple pages depending on the response. What would the best way to do so? The most naive way I could think of is to retrieve all the pages first and then work with them rather than processing the pages one at a time.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source