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_policy = tidy_policy_body_auto(),
call = rlang::caller_env()
)Arguments
- req
(
httr2_request) Ahttr2::request()object.- tidy_policy
(
nectar_tidy_policyorNULL) A tidying policy prepared withtidy_policy_prepare(). By default,tidy_policy_body_auto()is used to automatically applyresp_body_auto()to responses.- 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.
See also
Other opinionated request functions:
req_auth_api_key(),
req_init(),
req_modify(),
req_pagination_policy(),
req_prepare()
Other opinionated response parsers:
resp_tidy(),
resp_tidy_json(),
resp_tidy_unknown(),
tidy_policy_body_auto(),
tidy_policy_json(),
tidy_policy_prepare(),
tidy_policy_unknown()
Examples
req <- httr2::request("https://example.com")
req_tidy_policy(
req,
tidy_policy_json()
)
#> <nectar_request/httr2_request>
#> GET https://example.com
#> Body: empty
#> Policies:
#> * resp_tidy: <nectar_tidy_policy>