If you have implemented the full nectar
framework, use resp_tidy()
directly to parse your responses. We may continue to support
resp_parse()
, but it is most useful as a bridge to the full framework.
httr2
provides two methods for performing requests:
httr2::req_perform()
, which returns a single httr2::response()
object,
and httr2::req_perform_iterative()
, which returns a list of
httr2::response()
objects. This function automatically determines whether
a single response or multiple responses have been returned, and parses the
responses appropriately.
Usage
resp_parse(resps, ...)
# Default S3 method
resp_parse(
resps,
...,
arg = rlang::caller_arg(resps),
call = rlang::caller_env()
)
# S3 method for class 'httr2_response'
resp_parse(resps, ..., response_parser = resp_tidy)
Arguments
- resps
(
httr2_response
,nectar_responses
, orlist
) A singlehttr2::response()
object (as returned byhttr2::req_perform()
) or a list of such objects (as returned byreq_perform_opinionated()
orhttr2::req_perform_iterative()
).- ...
Additional arguments passed on to the
response_parser
function (in addition toresps
).- arg
(
length-1 character
) An argument name as a string. This argument will be mentioned in error messages as the input that is at the origin of a problem.- 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.- response_parser
(
function
) A function to parse the server response (resp
). Defaults tohttr2::resp_body_json()
, since JSON responses are common. Set this toNULL
to return the raw response fromhttr2::req_perform()
.
Value
The response parsed by the response_parser
. If resps
was a list,
the parsed responses are concatenated when possible. Unlike
httr2::resps_data, this function does not concatenate raw vector
responses.