Web Technologies

Open Notify is an open source project, developed and maintained by Nathan Bergey, to provide a simple application programming interface (API) for some of NASA’s data.
Open Notify’s APIs allow you to make 2 types of requests1:

http://api.open-notify.org/iss-now.json



http://api.open-notify.org/iss-now.json


curl to make request.
Craft URL from a base URL (endpoint) and parameters
http://api.open-notify.org/iss-now.json

Most shells have curl command for making HTTP requests.
{"timestamp": 1776564579, "iss_position": {"latitude": "-66.4643", "longitude": "-47.3791"}, "message": "success"}
$timestamp
[1] 1776564579
$iss_position
$iss_position$longitude
[1] "-47.3791"
$iss_position$latitude
[1] "-66.4643"
$message
[1] "success"
Use an HTTP library, e.g. "httr2"
Open Notify’s ISS location:
Create a request object with request(), this define your base request.
Complete the full path, via req_url_path_append(), by appending the JSON file name.
Submit request with req_perform().
Extract data with resp_body_json()
<httr2_response>
GET http://api.open-notify.org/iss-now.json
Status: 200 OK
Content-Type: application/json
Body: In memory (112 bytes)
[1] "method" "url" "status_code" "headers" "body"
[6] "request" "cache"
$timestamp
[1] 1776564579
$iss_position
$iss_position$longitude
[1] "-47.3791"
$iss_position$latitude
[1] "-66.4643"
$message
[1] "success"
"httr2" is the modern standard for API interaction in R. It treats the API request as a conversation.
Pros:
API-First: Built specifically for modern web requirements like OAuth, API keys, and custom headers.
Pipe-friendly: Works with |> (e.g., request(url) |> req_perform()).
Robust: It has built-in features for retrying failed requests, rate-limiting, and pausing between calls.
Informative: It gives you easy access to HTTP status codes.
Cons:
Dependency: Requires installing the package.
Learning curve: Slightly more complex for a simple one-off file download.
BART Legacy API
https://www.bart.gov/schedules/developers/api
Like many other APIs, BART Legacy API requires an API key.
Usually, you would have to register with the API provider to obtain an API key.
Good news: BART lets you use their Legacy API key without having to register.
Legacy API key: MW9S-E7SL-26DU-VV8V
For those interested in getting their own API key, BART’s API also provides this kind of key.
In order to use an API, the first step consists of finding and reading the API’s Documentation.
The Documentation defines what information you can ask for and how to format your request.
Keep in mind that some API’s provide minimal or almost no documentation, while others provide extensive—and sometimes not-user-friendly—documentation.
BART Legacy API provides a fair amount of documentation but it can feel a bit intimidating to a beginner user.
<httr2_request>
GET https://api.bart.gov/api/stn.aspx
Body: empty
<httr2_response>
GET https://api.bart.gov/api/stn.aspx?cmd=stns&key=MW9S-E7SL-26DU-VV8V&json=y
Status: 200 OK
Content-Type: application/json
Body: In memory (10289 bytes)
<httr2_response>
GET
https://api.bart.gov/api/stn.aspx?cmd=stninfo&orig=DBRK&key=MW9S-E7SL-26DU-VV8V&json=y
Status: 200 OK
Content-Type: application/json
Body: In memory (1810 bytes)
$`?xml`
$`?xml`$`@version`
[1] "1.0"
$`?xml`$`@encoding`
[1] "utf-8"
$root
$root$`@id`
[1] "1"
$root$uri
$root$uri$`#cdata-section`
[1] "http://api.bart.gov/api/stn.aspx?cmd=stninfo&orig=DBRK&json=y"
$root$stations
$root$stations$station
$root$stations$station$name
[1] "Downtown Berkeley"
$root$stations$station$abbr
[1] "DBRK"
$root$stations$station$gtfs_latitude
[1] "37.870104"
$root$stations$station$gtfs_longitude
[1] "-122.268133"
$root$stations$station$address
[1] "2160 Shattuck Avenue"
$root$stations$station$city
[1] "Berkeley"
$root$stations$station$county
[1] "alameda"
$root$stations$station$state
[1] "CA"
$root$stations$station$zipcode
[1] "94704"
$root$stations$station$north_routes
$root$stations$station$north_routes$route
$root$stations$station$north_routes$route[[1]]
[1] "ROUTE 3"
$root$stations$station$north_routes$route[[2]]
[1] "ROUTE 8"
$root$stations$station$south_routes
$root$stations$station$south_routes$route
$root$stations$station$south_routes$route[[1]]
[1] "ROUTE 4"
$root$stations$station$south_routes$route[[2]]
[1] "ROUTE 7"
$root$stations$station$north_platforms
$root$stations$station$north_platforms$platform
$root$stations$station$north_platforms$platform[[1]]
[1] "1"
$root$stations$station$south_platforms
$root$stations$station$south_platforms$platform
$root$stations$station$south_platforms$platform[[1]]
[1] "2"
$root$stations$station$platform_info
[1] ""
$root$stations$station$intro
$root$stations$station$intro$`#cdata-section`
[1] "The Downtown Berkeley BART Station is located on Shattuck Avenue between Allston Way and Addison Street. It is conveniently located close to the University of California campus and to many shops, restaurants, theaters and other attractions, and has valet bike parking. Public restrooms are available.Maps of this stationStation MapTransit StopsTransit RoutesSchedules and Fares"
$root$stations$station$cross_street
$root$stations$station$cross_street$`#cdata-section`
[1] "Between: Center St. & Allston Way"
$root$stations$station$food
$root$stations$station$food$`#cdata-section`
[1] "Nearby restaurant reviews from <a href=\"http://www.yelp.com/search?find_desc=Restaurant+&ns=1&rpp=10&find_loc=2160 Shattuck Avenue Berkeley, CA 94704\">yelp.com</a>"
$root$stations$station$shopping
$root$stations$station$shopping$`#cdata-section`
[1] "Local shopping from <a href=\"http://www.yelp.com/search?find_desc=Shopping+&ns=1&rpp=10&find_loc=2160 Shattuck Avenue Berkeley, CA 94704\">yelp.com</a>"
$root$stations$station$attraction
$root$stations$station$attraction$`#cdata-section`
[1] "More station area attractions from <a href=\"http://www.yelp.com/search?find_desc=+&ns=1&rpp=10&find_loc=2160 Shattuck Avenue Berkeley, CA 94704\">yelp.com</a> and <a href=\"http://www.sfgate.com/cgi-bin/article.cgi?f=/c/a/2008/03/13/NSENVEA1M.DTL&type=travel\">sfgate.com</a>"
$root$stations$station$link
$root$stations$station$link$`#cdata-section`
[1] "http://www.bart.gov/stations/DBRK"
$root$message
[1] ""
