This constructor stores a response tidying function and arguments so the same tidying strategy can be reused across requests.
Arguments
- tidy_fn
(
function) A function that will be invoked byresp_tidy()to tidy a response.- ...
(
any) Arguments to pass totidy_fn.
See also
Other opinionated response parsers:
req_tidy_policy(),
resp_tidy(),
resp_tidy_json(),
resp_tidy_unknown(),
tidy_policy_body_auto(),
tidy_policy_json(),
tidy_policy_unknown()
Examples
tidy_policy_prepare(httr2::resp_body_json, simplifyVector = TRUE)
#> $tidy_fn
#> function (resp, check_type = TRUE, simplifyVector = FALSE, ...)
#> {
#> check_response(resp)
#> check_installed("jsonlite")
#> key <- body_cache_key("json", simplifyVector = simplifyVector,
#> ...)
#> if (env_has(resp$cache, key)) {
#> return(resp$cache[[key]])
#> }
#> resp_check_content_type(resp, valid_types = "application/json",
#> valid_suffix = "json", check_type = check_type)
#> text <- resp_body_string(resp, "UTF-8")
#> resp$cache[[key]] <- jsonlite::fromJSON(text, simplifyVector = simplifyVector,
#> ...)
#> resp$cache[[key]]
#> }
#> <bytecode: 0x55d53faa68c0>
#> <environment: namespace:httr2>
#>
#> $tidy_args
#> $tidy_args$simplifyVector
#> [1] TRUE
#>
#>
#> attr(,"class")
#> [1] "nectar_tidy_policy"