The batched counterpart to post_json(), for a JSON or GraphQL endpoint
answering many queries. Keyed on the URL and the body together, so two
different queries to the same endpoint do not collide.
Usage
post_json_many(
url,
bodies = list(),
source = "API",
timeout = 20,
max_tries = 3,
headers = NULL,
throttle = NULL,
max_active = 6,
progress = FALSE,
secret_query = NULL
)Arguments
- url
The endpoint URL.
- bodies
A list of request bodies, one per request. Each is serialized as JSON.
- source
A friendly label for the service, used in the user-facing message. For example
"MyGene".- timeout
Seconds before a request is abandoned.
- max_tries
Total attempts, including the first. Note that httr2 does not honor this under parallel performance.
- headers
A named list of headers, all marked sensitive.
- throttle
A throttle spec. See
req_defaults().- max_active
Maximum requests in flight at once.
- progress
Passed to
httr2::req_perform_parallel().FALSEby default, because the usual caller is a Shiny app that renders its own.- secret_query
A named list of query-string credentials, applied to every request in the batch at dispatch. See
redact_secrets().
Details
Read the sections on perform_many() first.
Examples
cache_reset()
breaker_reset()
httr2::with_mocked_responses(
function(req) {
httr2::response(
status_code = 200,
headers = list(`content-type` = "application/json"),
body = charToRaw('{"data":{}}')
)
},
length(post_json_many(
"https://gnomad.broadinstitute.org/api",
bodies = list(list(query = "{ a }"), list(query = "{ b }")),
source = "gnomAD"
))
)
#> [1] 2