Skip to contents

Get JSON from an API

Usage

getJson(url)

Arguments

url

character(1). Uniform Resource Locator (URL).

Value

list.

Details

Requires httr2 package to be installed.

Note

Updated 2023-09-14.

Examples

## Access the UCSC Genome Browser API.
url <- pasteUrl(
    "api.genome.ucsc.edu",
    "list",
    "ucscGenomes",
    protocol = "https"
)
if (goalie::isAnExistingUrl(url)) {
    json <- getJson(url)
    print(names(json))
}
#> [1] "downloadTime"      "downloadTimeStamp" "dataTime"         
#> [4] "dataTimeStamp"     "ucscGenomes"      

## Access Ensembl genome assembly metadata.
## The Ensembl REST API server is prone to connection issues, so keeping
## disabled here in the working example.
## > url <- pasteUrl(
## >     "rest.ensembl.org",
## >     "info",
## >     "assembly",
## >     paste0(
## >         "Homo sapiens",
## >         "?", "content-type=application/json"
## >     ),
## >     protocol = "https"
## > )
## > if (goalie::isAnExistingUrl(url)) {
## >     json <- getJson(url)
## >     print(names(json))
## > }