Hacker News new | past | comments | ask | show | jobs | submit login

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)



Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: