Skip to content

Use req_throttle() to ensure that repeated calls to req_perform() never exceed a specified rate.

Usage

req_throttle(req, rate, realm = NULL)

Arguments

req

A request.

rate

Maximum rate, i.e. maximum number of requests per second. Usually easiest expressed as a fraction, number_of_requests / number_of_seconds, e.g. 15 requests per minute is 15 / 60.

realm

An unique identifier that for throttle pool. If not supplied, defaults to the hostname of the request.

Value

A modified HTTP request.

See also

req_retry() for another way of handling rate-limited APIs.

Examples

# Ensure server will never recieve more than 10 requests a minute
request("https://example.com") %>%
  req_throttle(rate = 10 / 60)
#> <httr2_request>
#> GET https://example.com
#> Body: empty
#> Policies:
#>throttle_delay: a function