Skip to contents

Executes an HTTP request function with exponential backoff retry on transient failures (429 rate limit, 5xx server errors).

Usage

http_retry(request_fn, max_retries = 2, backoff_base = 2)

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).

Value

The httr2 response object from a successful request.

See also

Examples

if (FALSE) { # \dontrun{
result <- http_retry(function() {
  httr2::request("https://api.example.com/data") |>
    httr2::req_perform()
})
} # }