Use httr::GET() to make a request to the WMATA API and return the parsed list from the JSON data. The function uses httr::RETRY(), so the call will repeat up to three times if there is a failure (often from a rate limit).

wmata_api(path, query = NULL, ..., level, api_key = wmata_key())

Arguments

path

The path to an API endpoint (e.g., "Bus.svc/json/jStopSchedule")

query

Additional queries also passed, possibly your key if need be.

...

Arguments passed to jsonlite::fromJSON() for parsing.

level

If parsed JSON is a list, select only this element. Useful if the list is length one containing a data frame or some other object.

api_key

Subscription key which provides access to this API. Defaults Sys.getenv("WMATA_KEY") via wmata_key().

Value

A single JSON string.

Details

This function was modified from 'zamorarr/wmata' on GitHub: https://github.com/zamorarr/wmata/blob/master/R/api.r

Examples

if (FALSE) {
wmata_api("Rail.svc/json/jLines", query = list(LineCode = "RD"))
}