Application Programming Interface
Provides any interface to allow for a programmer to get data from another source in a programmatic way.
1. RESTful API: Allows a client to request the current data from the server.
(Ex: What is the current temperature in Champaign, IL?)
2. Publish/Subscribe API: Allows a client to subscribe to recieve updates
about changes/events in data.
(Ex: An update will be published to all clients
when the current temperature in Champaign, IL changes.)
The CUMTD API is a RESTful API.
Thier documentation tells us:
The RESTful endpoints use the HTTP GET verb with query string parameters.
http://cs.illinois.edu/?a=3&b=5&s=Hello
http://cs.illinois.edu/?a=3&b=5&s=Hello ----------------------- --------------- URL Query String
http://cs.illinois.edu/?a=3&b=5&s=Hello ----------------------- --------------- URL { a = "3", b = "5", s = "Hello" }
GetDeparturesByStop Method Documentation
demo_cumtd
# Load the urllib library import urllib ... # Construct a Python dictionary parameters = { "key": myKey, "stop_id": "IU" } # Construct the full URL url = "https://developer.cumtd.com/api/v2.2/json/" + "GetDeparturesByStop?" + urllib.urlencode( parameters ) # Read the response response = urllib.urlopen( url )
# Load the json library import json ... # Parse a JSON string into a Python dictionary dictionary = json.load( response )
[ { "route": "5E Green", "expected": 3 }, { "route": "12W Teal", "expected": 5 }, { "route": "22S Illini", "expected": 6 }, { "route": "13N Silver", "expected": 10 }, ]