API Calls: Fetch, Parse, and Compute
Problem Given a paginated HTTP API, fetch all pages of records, parse them, and compute an aggregate over the full dataset (e.g. total or average of a numeric field). The API returns one page per request and signals when there are no more pages.
Input / Output
- Input: an API endpoint that accepts a page number/cursor and returns a page of records.
- Output: the computed aggregate across every record.
Constraints
- The number of pages is not known up front; loop until an empty (or last) page.
- Handle transient network errors with retries.
- Records may span many pages, so avoid holding everything in memory if a streaming aggregate suffices.
Example
- GET /data?page=1..N until a page comes back empty; accumulate a running sum and count -> return sum/count as the average.
added …