In some API clients I found myself doing these things:
class WegowClient(RequestsClient):
def event_feed(self, page: int | None = None) -> EventFeedResponse:
return self._perform_request(EventFeedEndpoint(page))
def get_events(self) -> Iterable[Event]:
"""Returns an iterator containing all concerts"""
next_page = None
while True:
response = self.event_feed(page=next_page)
yield from response.events
next_page = response.next_page
if next_page is None:
break
It would be nice to have a way to define in an Endpoint how its pagination works so we can easilly return yield all objects from a paginated endpoint.