Skip to contents

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,
  ttl = 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. A retry pass re-sends only the entries that came back rate_limited, timeout, or a 5xx, honoring Retry-After between passes. See the retry section on perform_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(). 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().

ttl

Seconds a cached success stays fresh, applied to every entry in the batch. NULL, the default, means the configured lifetime from BIOHTTP_CACHE_TTL. See cached().

Value

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

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('{"data":{}}')
    )
  },
  length(post_json_many(
    "https://gnomad.broadinstitute.org/api",
    bodies = list(list(query = "{ a }"), list(query = "{ b }")),
    source = "gnomAD"
  ))
)
#> [1] 2