2 ms·
SDKs should typically return a lazy iterator in languages which support it, so caller do not even care about pagination and just iterate on it until they don't
by progval 4y ago
SDKs should typically return a lazy iterator in languages which support it, so caller do not even care about pagination and just iterate on it until they don't want any more data; while the SDK fetches new pages when needed.
In pseudo-Python:
def get_stuff():
url = "https://example.org/api.php"
while url:
response = requests.get(url)
yield from response.json()
url = parse_link(response.headers["link"]).next
and you call it with:
for item in get_stuff():
print(item)
- deleted 4y ago[deleted]