Skip to contents

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
)

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 in queries.

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. 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(). FALSE by 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().

Value

A list of envelopes, the same length and order as queries.

Details

Read the sections on perform_many() first. The same two rules apply: pass requests for one host, and supply a throttle.

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