R: HTTP request object

HttpRequest {crul} | R Documentation

## 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
`auth` | result of a call to the `auth` function, e.g. `auth(user = "foo", pwd = "bar")`
`headers` | (list) a named list of headers
`handle` | A handle, see `handle`
`progress` | a function with logic for printing a progress bar for an HTTP request, ultimiately passed down to curl. only supports httr::progress() for now

### Details

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.

### See Also

post-requests, delete-requests, http-headers, writing-options

### Examples

    ## Not run:
    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"
      )
    )

    ## End(Not run)

[Package crul version 0.6.0 Index]