Skip to contents

Many APIs provide API keys that can be used to authenticate requests (or, often, provide other information about the user). This function helps to apply those keys to requests.

Usage

req_auth_api_key(
  req,
  parameter_name,
  ...,
  api_key = NULL,
  location = c("header", "query", "cookie"),
  call = rlang::caller_env()
)

Arguments

req

(httr2_request) A httr2::request() object.

parameter_name

(length-1 character) The name of the parameter to use in the header, query, or cookie.

...

These dots are for future extensions and must be empty.

api_key

(length-1 character or NULL) The API key to use. If this value is NULL, req is returned unchanged.

location

(length-1 character) Where the API key should be passed. One of "header" (default), "query", or "cookie".

call

(environment) The environment from which a function was called, e.g. rlang::caller_env() (the default). The environment will be mentioned in error messages as the source of the error. This argument is particularly useful for functions that are intended to be called as utilities inside other functions.

Value

A httr2::request() object with additional class nectar_request.