Skip to contents

object that handled all aspects of a request

Public fields

method

(character) http method

uri

(character) a uri

scheme

(character) scheme (http or https)

host

(character) host (e.g., stuff.org)

path

(character) path (e.g., foo/bar)

query

(character) query params, named list

body

(character) named list

headers

(character) named list

skip_port_stripping

(logical) whether to strip thhe port

hash

(character) a named list - internal use

opts

(character) options - internal use

disk

(logical) xx

fields

(various) request body details

output

(various) request output details, disk, memory, etc

Methods


Method new()

Create a new Request object

Usage

Request$new(method, uri, body, headers, opts, disk, fields, output)

Arguments

method

(character) the HTTP method (i.e. head, options, get, post, put, patch or delete)

uri

(character) request URI

body

(character) request body

headers

(named list) request headers

opts

(named list) options internal use

disk

(boolean), is body a file on disk

fields

(various) post fields

output

(various) output details

Returns

A new Request object


Method to_hash()

Convert the request to a list

Usage

Request$to_hash()

Returns

list


Method from_hash()

Convert the request to a list

Usage

Request$from_hash(hash)

Arguments

hash

a list

Returns

a new Request object


Method clone()

The objects of this class are cloneable with this method.

Usage

Request$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

url <- "https://eu.httpbin.org/post"
body <- list(foo = "bar")
headers <- list(
  `User-Agent` = "libcurl/7.54.0 r-curl/3.2 crul/0.5.2",
  `Accept-Encoding` = "gzip, deflate",
  Accept = "application/json, text/xml, application/xml, */*"
)

(x <- Request$new("POST", url, body, headers))
#> <Request>
#>   Public:
#>     body: foo=bar
#>     clone: function (deep = FALSE) 
#>     disk: NULL
#>     fields: NULL
#>     from_hash: function (hash) 
#>     hash: NULL
#>     headers: list
#>     host: eu.httpbin.org
#>     initialize: function (method, uri, body, headers, opts, disk, fields, output) 
#>     method: post
#>     opts: NULL
#>     output: NULL
#>     path: post
#>     query: NA
#>     scheme: https
#>     skip_port_stripping: FALSE
#>     to_hash: function () 
#>     uri: https://eu.httpbin.org/post
#>   Private:
#>     parsed_uri: function (uri) 
#>     without_standard_port: function (uri) 
x$body
#> [1] "foo=bar"
x$method
#> [1] "post"
x$uri
#> [1] "https://eu.httpbin.org/post"
x$host
#> [1] "eu.httpbin.org"
x$path
#> [1] "post"
x$headers
#> $`User-Agent`
#> [1] "libcurl/7.54.0 r-curl/3.2 crul/0.5.2"
#> 
#> $`Accept-Encoding`
#> [1] "gzip, deflate"
#> 
#> $Accept
#> [1] "application/json, text/xml, application/xml, */*"
#> 
h <- x$to_hash()
x$from_hash(h)
#> <Request>
#>   Public:
#>     body: foo=bar
#>     clone: function (deep = FALSE) 
#>     disk: NULL
#>     fields: NULL
#>     from_hash: function (hash) 
#>     hash: NULL
#>     headers: list
#>     host: eu.httpbin.org
#>     initialize: function (method, uri, body, headers, opts, disk, fields, output) 
#>     method: post
#>     opts: NULL
#>     output: NULL
#>     path: post
#>     query: NA
#>     scheme: https
#>     skip_port_stripping: FALSE
#>     to_hash: function () 
#>     uri: https://eu.httpbin.org/post
#>   Private:
#>     parsed_uri: function (uri) 
#>     without_standard_port: function (uri)