Safely retry a request until it succeeds, as defined by the
parameter, which by default means a response for which
FALSE. Will also retry on error conditions raised by the underlying curl code,
but if the last retry still raises one,
RETRY will raise it again with
It is designed to be kind to the server: after each failure
randomly waits up to twice as long. (Technically it uses exponential
backoff with jitter, using the approach outlined in
If the server returns status code 429 and specifies a
retry-after value, that
value will be used instead, unless it's smaller than
RETRY(verb, url = NULL, config = list(), ..., body = NULL, encode = c("multipart", "form", "json", "raw"), times = 3, pause_base = 1, pause_cap = 60, pause_min = 1, handle = NULL, quiet = FALSE, terminate_on = NULL, terminate_on_success = TRUE)
Name of verb to use.
the url of the page to retrieve
One of the following:
If the body is a named list, how should it be encoded? Can be one of form (application/x-www-form-urlencoded), multipart, (multipart/form-data), or json (application/json).
For "multipart", list elements can be strings or objects created by
Maximum number of requests to attempt.
This method uses exponential back-off with
full jitter - this means that each request will randomly wait between 0
Minimum time to wait in the backoff; generally only necessary if you need pauses less than one second (which may not be kind to the server, use with caution!).
The handle to use with this request. If not
supplied, will be retrieved and reused from the
Optional vector of numeric HTTP status codes that if found
on the response will terminate the retry process. If
The last response. Note that if the request doesn't succeed after
times times this will be a failed request, i.e. you still need
# Succeeds straight away RETRY("GET", "http://httpbin.org/status/200")#> Response [http://httpbin.org/status/200] #> Date: 2018-12-17 20:44 #> Status: 200 #> Content-Type: text/html; charset=utf-8 #> <EMPTY BODY># Never succeeds RETRY("GET", "http://httpbin.org/status/500")#>#>#> Response [http://httpbin.org/status/500] #> Date: 2018-12-17 20:44 #> Status: 500 #> Content-Type: text/html; charset=utf-8 #> <EMPTY BODY># Invalid hostname generates curl error condition and is retried but eventually # raises an error condition. RETRY("GET", "http://invalidhostname/")#> Error in UseMethod("http_error"): no applicable method for 'http_error' applied to an object of class "c('simpleError', 'error', 'condition')"