Skip to contents

APIs generally have a specified method for requesting multiple pages of results (or sometimes two or three methods). The methods are sometimes documented within a given endpoint, and sometimes documented at the "top" of the documentation. Use this function to attach a pagination policy to a request, so that req_perform_opinionated() can automatically handle pagination.

Usage

req_pagination_policy(req, pagination_fn, call = rlang::caller_env())

Arguments

req

(httr2_request) A httr2::request() object.

pagination_fn

(function) A function that takes the previous response (resp) to generate the next request in a call to httr2::req_perform_iterative(). This function can usually be generated using one of the iteration helpers described in httr2::iterate_with_offset(). This function will be extracted from the request by req_perform_opinionated() and passed on as next_req to httr2::req_perform_iterative().

call

(environment) The environment from which a function was called, e.g. rlang::caller_env() (the default). The environment will be mentioned in error messages as the source of the error. This argument is particularly useful for functions that are intended to be called as utilities inside other functions.

Value

A httr2::request() object with additional class nectar_request.

See also

Other opinionated request functions: req_init(), req_modify(), req_prepare(), req_tidy_policy()

Examples

req <- httr2::request("https://example.com")
req_pagination_policy(req, httr2::iterate_with_offset("page"))
#> <nectar_request/httr2_request>
#> GET https://example.com
#> Body: empty
#> Policies:
#>pagination: a list