Skip to contents

Modify the basic request for an API by adding a path and any other path-specific properties.

Usage

req_modify(
  req,
  ...,
  path = NULL,
  query = NULL,
  body = NULL,
  mime_type = NULL,
  method = NULL
)

Arguments

req

A httr2::request() object.

...

These dots are for future extensions and must be empty.

path

The route to an API endpoint. Optionally, a list or character vector with the path as one or more unnamed arguments (which will be concatenated with "/") plus named arguments to glue::glue() into the path.

query

An optional list or character vector of parameters to pass in the query portion of the request. Can also include a .multi argument to pass to httr2::req_url_query() to control how elements containing multiple values are handled.

body

An object to use as the body of the request. If any component of the body is a path, pass it through fs::path() or otherwise give it the class "fs_path" to indicate that it is a path.

mime_type

A character scalar indicating the mime type of any files present in the body. Some APIs allow you to leave this as NULL for them to guess.

method

If the method is something other than GET or POST, supply it. Case is ignored.

Value

A httr2::request() object.

Examples

req_base <- req_setup(
  "https://example.com",
  user_agent = "my_api_client (https://my.api.client)"
)
req <- req_modify(req_base, path = c("specific/{path}", path = "endpoint"))
req
#> <httr2_request>
#> GET https://example.com/specific/endpoint
#> Body: empty
#> Options:
#>useragent: 'my_api_client (https://my.api.client)'
req <- req_modify(req, query = c("param1" = "value1", "param2" = "value2"))
req
#> <httr2_request>
#> GET https://example.com/specific/endpoint?param1=value1&param2=value2
#> Body: empty
#> Options:
#>useragent: 'my_api_client (https://my.api.client)'