Skip to contents

For a given API, the base_url and user_agent will almost always be the same. Use this function to prepare that piece of the request once for easy reuse.

Usage

req_setup(base_url, ..., user_agent = "nectar (https://nectar.api2r.org)")

Arguments

base_url

The part of the url that is shared by all calls to the API. In some cases there may be a family of base URLs, from which you will need to choose one.

...

These dots are for future extensions and must be empty.

user_agent

A string to identify where this request is coming from. It's polite to set the user agent to identify your package, such as "MyPackage (https://mypackage.com)".

Value

A httr2::request() object.

Examples

req_setup("https://example.com")
#> <httr2_request>
#> GET https://example.com
#> Body: empty
#> Options:
#>useragent: 'nectar (https://nectar.api2r.org)'
req_setup(
  "https://example.com",
  user_agent = "my_api_client (https://my.api.client)"
)
#> <httr2_request>
#> GET https://example.com
#> Body: empty
#> Options:
#>useragent: 'my_api_client (https://my.api.client)'