req <- request(example_url()) |>
req_url_path("/iris") |>
req_throttle(10) |>
req_url_query(limit = 50)
# If you don't know the total number of pages in advance, you can
# provide a `resp_complete()` callback
is_complete <- function(resp) {
length(resp_body_json(resp)$data) == 0
}
resps <- req_perform_iterative(
req,
next_req = iterate_with_offset("page_index", resp_complete = is_complete),
max_reqs = Inf
)
if (FALSE) {
# Alternatively, if the response returns the total number of pages (or you
# can easily calculate it), you can use the `resp_pages()` callback which
# will generate a better progress bar.
resps <- req_perform_iterative(
req |> req_url_query(limit = 1),
next_req = iterate_with_offset(
"page_index",
resp_pages = function(resp) resp_body_json(resp)$pages
),
max_reqs = Inf
)
}
Run the code above in your browser using DataLab