GET/POST from brainmaps API with optional retry / cache
Source:R/brainmaps-api.R
brainmaps_fetch.Rd
brainmaps_fetch
calls the brainmaps API with optional
request cache and retries.
brainmaps_clear_cache
clears the cache used by brainmaps_fetch
Usage
brainmaps_fetch(
url,
body = NULL,
parse.json = TRUE,
cache = FALSE,
retry = 0L,
include_headers = FALSE,
simplifyVector = TRUE,
...
)
brainmaps_clear_cache()
Arguments
- url
Full URL for brainmaps API endpoint
- body
an R list with parameters that will be converted with
jsonlite::toJSON
and then passed on toPOST
. You can also pass aJSON
character vector to have more control of theJSON
encoding.- parse.json
Whether or not to parse a JSON response to an R object (default
TRUE
)- cache
Whether or not to cache responses (default
FALSE
)- retry
The number of times to retry the operation (default 0,
FALSE
=>0
andTRUE
=>3). See the documentation of thetimes
argument ofhttr::RETRY
for further details.- include_headers
Whether to include basic headers from the http request as attributes on the parsed JSON object (default
TRUE
) whenparse.json=TRUE
.- simplifyVector
Whether to use
jsonlite::simplifyVector
- ...
additional arguments passed to the
httr::{RETRY}
function. This may include aconfig
list other named parameters etc.
Examples
if (FALSE) { # \dontrun{
brainmaps_fetch("https://brainmaps.googleapis.com/v1/volumes")
# retry up to 4 times on failure
brainmaps_fetch("https://brainmaps.googleapis.com/v1/volumes", retry=4)
# cache results
brainmaps_fetch("https://brainmaps.googleapis.com/v1/volumes", cache=TRUE)
# use arbitrary curl/httr options (see httr_options())
httr::with_config(httr::verbose(), {
brainmaps_fetch("https://brainmaps.googleapis.com/v1/volumes")
})
} # }
# \donttest{
brainmaps_clear_cache()
#> [1] TRUE
# }