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(resp, ...)
# S3 method for default
resp_parse(
resp,
...,
arg = rlang::caller_arg(resp),
call = rlang::caller_env()
)
# S3 method for httr2_response
resp_parse(resp, ..., response_parser = httr2::resp_body_json)
Arguments
- resp
A single
httr2::response()
object (as returned byhttr2::req_perform()
) or a list of such objects (as returned byhttr2::req_perform_iterative()
).- ...
Additional arguments passed on to the
response_parser
function (in addition toresp
).- arg
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
The execution environment of a currently running function, e.g. caller_env(). The function will be mentioned in error messages as the source of the error. See the call argument of abort() for more information.
- response_parser
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 resp
was a list,
the parsed responses are concatenated when possible. Unlike
httr2::resps_data, this function does not concatenate raw vector
responses.