Skip to content

Use an arbitrary verb.

Usage

VERB(
  verb,
  url = NULL,
  config = list(),
  ...,
  body = NULL,
  encode = c("multipart", "form", "json", "raw"),
  handle = NULL
)

Arguments

verb

Name of verb to use.

url

the url of the page to retrieve

config

Additional configuration settings such as http authentication (authenticate()), additional headers (add_headers()), cookies (set_cookies()) etc. See config() for full details and list of helpers.

...

Further named parameters, such as query, path, etc, passed on to modify_url(). Unnamed parameters will be combined with config().

body

One of the following:

  • FALSE: No body. This is typically not used with POST, PUT, or PATCH, but can be useful if you need to send a bodyless request (like GET) with VERB().

  • NULL: An empty body

  • "": A length 0 body

  • upload_file("path/"): The contents of a file. The mime type will be guessed from the extension, or can be supplied explicitly as the second argument to upload_file()

  • A character or raw vector: sent as is in body. Use content_type() to tell the server what sort of data you are sending.

  • A named list: See details for encode.

encode

If the body is a named list, how should it be encoded? Can be one of form (application/x-www-form-urlencoded), multipart, (multipart/form-data), or json (application/json).

For "multipart", list elements can be strings or objects created by upload_file(). For "form", elements are coerced to strings and escaped, use I() to prevent double-escaping. For "json", parameters are automatically "unboxed" (i.e. length 1 vectors are converted to scalars). To preserve a length 1 vector as a vector, wrap in I(). For "raw", either a character or raw vector. You'll need to make sure to set the content_type() yourself.

handle

The handle to use with this request. If not supplied, will be retrieved and reused from the handle_pool() based on the scheme, hostname and port of the url. By default httr requests to the same scheme/host/port combo. This substantially reduces connection time, and ensures that cookies are maintained over multiple requests to the same host. See handle_pool() for more details.

Value

A response() object.

See also

Other http methods: BROWSE(), DELETE(), GET(), HEAD(), PATCH(), POST(), PUT()

Examples

r <- VERB(
  "PROPFIND", "http://svn.r-project.org/R/tags/",
  add_headers(depth = 1), verbose()
)
stop_for_status(r)
content(r)
#> {xml_document}
#> <multistatus xmlns:D="DAV:">
#>  [1] <D:response xmlns:S="http://subversion.tigris.org/xmlns/svn/" xmln ...
#>  [2] <D:response xmlns:S="http://subversion.tigris.org/xmlns/svn/" xmln ...
#>  [3] <D:response xmlns:S="http://subversion.tigris.org/xmlns/svn/" xmln ...
#>  [4] <D:response xmlns:S="http://subversion.tigris.org/xmlns/svn/" xmln ...
#>  [5] <D:response xmlns:S="http://subversion.tigris.org/xmlns/svn/" xmln ...
#>  [6] <D:response xmlns:S="http://subversion.tigris.org/xmlns/svn/" xmln ...
#>  [7] <D:response xmlns:S="http://subversion.tigris.org/xmlns/svn/" xmln ...
#>  [8] <D:response xmlns:S="http://subversion.tigris.org/xmlns/svn/" xmln ...
#>  [9] <D:response xmlns:S="http://subversion.tigris.org/xmlns/svn/" xmln ...
#> [10] <D:response xmlns:V="http://subversion.tigris.org/xmlns/dav/" xmln ...
#> [11] <D:response xmlns:S="http://subversion.tigris.org/xmlns/svn/" xmln ...
#> [12] <D:response xmlns:V="http://subversion.tigris.org/xmlns/dav/" xmln ...
#> [13] <D:response xmlns:V="http://subversion.tigris.org/xmlns/dav/" xmln ...
#> [14] <D:response xmlns:V="http://subversion.tigris.org/xmlns/dav/" xmln ...
#> [15] <D:response xmlns:V="http://subversion.tigris.org/xmlns/dav/" xmln ...
#> [16] <D:response xmlns:S="http://subversion.tigris.org/xmlns/svn/" xmln ...
#> [17] <D:response xmlns:S="http://subversion.tigris.org/xmlns/svn/" xmln ...
#> [18] <D:response xmlns:S="http://subversion.tigris.org/xmlns/svn/" xmln ...
#> [19] <D:response xmlns:S="http://subversion.tigris.org/xmlns/svn/" xmln ...
#> [20] <D:response xmlns:S="http://subversion.tigris.org/xmlns/svn/" xmln ...
#> ...

VERB("POST", url = "http://httpbin.org/post")
#> Response [http://httpbin.org/post]
#>   Date: 2022-05-04 12:20
#>   Status: 200
#>   Content-Type: application/json
#>   Size: 462 B
#> {
#>   "args": {}, 
#>   "data": "", 
#>   "files": {}, 
#>   "form": {}, 
#>   "headers": {
#>     "Accept": "application/json, text/xml, application/xml, */*", 
#>     "Accept-Encoding": "deflate, gzip, br", 
#>     "Content-Length": "0", 
#>     "Host": "httpbin.org", 
#> ...
VERB("POST", url = "http://httpbin.org/post", body = "foobar")
#> Response [http://httpbin.org/post]
#>   Date: 2022-05-04 12:20
#>   Status: 200
#>   Content-Type: application/json
#>   Size: 468 B
#> {
#>   "args": {}, 
#>   "data": "foobar", 
#>   "files": {}, 
#>   "form": {}, 
#>   "headers": {
#>     "Accept": "application/json, text/xml, application/xml, */*", 
#>     "Accept-Encoding": "deflate, gzip, br", 
#>     "Content-Length": "6", 
#>     "Host": "httpbin.org", 
#> ...