For a JSON or GraphQL POST. Caches on the URL and the body together, so two different queries to the same endpoint do not collide.
Usage
post_json(
url,
body,
source = "API",
timeout = 20,
max_tries = 3,
headers = NULL,
throttle = NULL,
secret_query = NULL
)Arguments
- url
The endpoint URL.
- body
A list, serialized as the JSON request body.
- source
A friendly label for the service.
- timeout
Seconds before the request is abandoned.
- max_tries
Total attempts, including the first.
- headers
A named list of headers, all marked sensitive.
- throttle
An optional throttle spec. See
req_defaults().- secret_query
A named list of query-string credentials, for a service that has no header form. Deliberately not part of the cache key, so it suits a credential that raises a rate limit and not one that changes the response. See
redact_secrets().
Value
An envelope. See envelope().
Examples
cache_reset()
breaker_reset()
httr2::with_mocked_responses(
list(httr2::response(
status_code = 200,
headers = list(`content-type` = "application/json"),
body = charToRaw('{"data":{"gene":{"gene_id":"ENSG00000012048"}}}')
)),
post_json(
"https://gnomad.broadinstitute.org/api",
body = list(query = "{ gene(gene_symbol: \"BRCA1\") { gene_id } }"),
source = "gnomAD"
)$data$data$gene$gene_id
)
#> [1] "ENSG00000012048"