The batched counterpart to get_json(). Assembles one request per entry in
queries, serves whatever the cache already holds, performs only the rest,
and caches the successes.
Usage
get_json_many(
base_url,
path = NULL,
queries = list(),
source = "API",
timeout = 15,
max_tries = 3,
headers = NULL,
throttle = NULL,
max_active = 6,
progress = FALSE,
secret_query = NULL,
ttl = NULL
)Arguments
- base_url
The service's base URL.
- path
A path appended to
base_url. Length 1 to use the same path for every request, or one per entry inqueries.- queries
A list of named lists, one per request. Blank values are dropped from each.
- 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. A retry pass re-sends only the entries that came back
rate_limited,timeout, or a 5xx, honoringRetry-Afterbetween passes. See the retry section onperform_many().- 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().- ttl
Seconds a cached success stays fresh, applied to every entry in the batch.
NULL, the default, means the configured lifetime fromBIOHTTP_CACHE_TTL. Seecached().
Details
Send requests for one host, and pass a throttle. perform_many() explains
both.
Examples
cache_reset()
breaker_reset()
httr2::with_mocked_responses(
function(req) {
httr2::response(
status_code = 200,
headers = list(`content-type` = "application/json"),
body = charToRaw('{"hits":[]}')
)
},
length(get_json_many(
"https://mygene.info/v3",
path = "query",
queries = list(list(q = "BRCA1"), list(q = "TP53")),
source = "MyGene"
))
)
#> [1] 2