Learn R Programming

crul (version 0.3.0)

HttpRequest: HTTP request object

Description

HTTP request object

Arguments

url
(character) A url. One of url or handle required.
opts
(list) curl options, a named list. See curl_options for available curl options
proxies
an object of class proxy, as returned from the proxy function. Supports one proxy for now
headers
(list) a named list of headers
handle
A handle, see handle

Details

This R6 class doesn't do actual HTTP requests as does HttpClient - but is for building requests to use for async HTTP requests in AsyncVaried Methods
get(path, query, disk, stream, ...)
Define a GET request
post(path, query, body, disk, stream, ...)
Define a POST request
put(path, query, body, disk, stream, ...)
Define a PUT request
patch(path, query, body, disk, stream, ...)
Define a PATCH request
delete(path, query, body, disk, stream, ...)
Define a DELETE request
head(path, disk, stream, ...)
Define a HEAD request
See HttpClient for information on parameters.

See Also

post-requests, http-headers, writing-options

Examples

Run this code
(x <- HttpRequest$new(url = "https://httpbin.org/get")$get())
x$url
x$payload

(x <- HttpRequest$new(url = "https://httpbin.org/post"))
x$post(body = list(foo = "bar"))

HttpRequest$new(
  url = "https://httpbin.org/get",
  headers = list(
    `Content-Type` = "application/json"
  )
)

Run the code above in your browser using DataLab