EnriqueSoria / EnriqueSoria/api_client_framework

Make an utility that returns an iterator for objects in paginated responses.

Open
#7 0 comments 0 reactions 0 assignees View on GitHub
enhancement
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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.