EnriqueSoria / EnriqueSoria/api_client_framework
Make an utility that returns an iterator for objects in paginated responses.
- Dominant language
- Python
- Stars
- 1
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
In some API clients I found myself doing these things:
```python
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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.