Skip to contents

API responses generally follow a structured format. Use this function to define a policy that will be used by resp_tidy() to extract the relevant portion of a response and wrangle it into a desired format.

Usage

req_tidy_policy(
  req,
  tidy_fn = resp_body_auto,
  tidy_args = list(),
  call = rlang::caller_env()
)

Arguments

req

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

tidy_fn

A function that will be invoked by resp_tidy() to tidy the response.

tidy_args

A list of additional arguments to pass to tidy_fn.

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.

Examples

req <- httr2::request("https://example.com")
req_tidy_policy(req, httr2::resp_body_json, list(simplifyVector = TRUE))
#> <httr2_request>
#> GET https://example.com
#> Body: empty
#> Policies:
#>resp_tidy: a list