Executes an HTTP request function with exponential backoff retry on transient failures (429 rate limit, 5xx server errors).
Arguments
- request_fn
Function that performs the HTTP request and returns an httr2 response object. Called with no arguments.
- max_retries
Integer. Maximum number of retry attempts. Default 2.
- backoff_base
Numeric. Base for exponential backoff in seconds. Delay is `backoff_base^attempt`. Default 2 (delays: 2s, 4s, 8s).
See also
Other http-utils:
http-utils,
http_validate_status()
Examples
if (FALSE) { # \dontrun{
result <- http_retry(function() {
httr2::request("https://api.example.com/data") |>
httr2::req_perform()
})
} # }
