async (version 0.0.0.9004)

http_get: Asynchronous HTTP GET request

Description

Start an HTTP GET request in the background, and report its completion via a deferred.

Usage

http_get(url, headers = character(), file = NULL,
  options = list(timeout = 600), on_progress = NULL)

Arguments

url

URL to connect to.

headers

HTTP headers to send.

file

If not NULL, it must be a string, specifying a file. The body of the response is written to this file.

options

Options to set on the handle. Passed to curl::handle_setopt().

on_progress

Progress handler function. It is only used if the response body is written to a file. See details below.

Value

Deferred object.

Progress bars

http_get can report on the progress of the download, via the on_progress argument. This is called with a list, with entries:

  • url: the specified url to download

  • handle: the curl handle of the request. This can be queried using curl::handle_data() to get the response status_code, the final URL (after redirections), timings, etc.

  • file: the file argument.

  • total: total bytes of the response. If this is unknown, it is set to zero.

  • current: already received bytes of the response.

See Also

Other asyncronous HTTP calls: http_head

Examples

Run this code
# NOT RUN {
afun <- async(function() {
  http_get("https://eu.httpbin.org/status/200")$
    then(function(x) x$status_code)
})
synchronise(afun())
# }

Run the code above in your browser using DataLab