| HttpRequest {crul} | R Documentation |
HTTP request object
url |
(character) A url. One of |
opts |
(list) curl options, a named list. See
|
proxies |
an object of class |
headers |
(list) a named list of headers |
handle |
A handle, see |
This R6 class doesn't do actual HTTP requests as does
HttpClient() - it is for building requests to use for async HTTP
requests in AsyncVaried()
Note that you can access HTTP verbs after creating an HttpRequest
object, just as you can with HttpClient. See examples for usage.
Also note that when you call HTTP verbs on a HttpRequest object you
don't need to assign the new object to a variable as the new details
you've added are added to the object itself.
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, ...)Define a HEAD request
method()Get the HTTP method (if defined) - returns character string
See HttpClient() for information on parameters.
post-requests, delete-requests, http-headers, writing-options
x <- HttpRequest$new(url = "https://httpbin.org/get")
## note here how the HTTP method is shown on the first line to the right
x$get()
## assign to a new object to keep the output
z <- x$get()
### get the HTTP method
z$method()
(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"
)
)