A web API is essentially a service offered by organizations to get access to their data and resources. For instance, Google will provide a service to find the distance between two locations.
The way that this works is that the API provider has a base URL that acts as the location for the API. For instance, the Google Distance Matrix API has a base URL of "https://maps.googleapis.com/maps/api/distancematrix/json?". If you navigate to that URL in your browser you will see data dispalyed. To use an API in our code we have to essentially request the URL from python and retrieve the data.
If you noticed, Matrix API base url didn't provide any interesting data. To tell the API provider what data to provide us, we have to pass in parameters along with the URL. These parameters are everything after the "?" which is in "key=value" pairs. For instance in the Matrix API I would say "origins=Pittsburgh" and "destinations=California", so the URL would look like: "https://maps.googleapis.com/maps/api/distancematrix/json?origins=Pittsburgh&destinations=California". Now if you go to the URL you can see the data it returns!
Now to call this in our code we will use the python http.request library. It will make a request to that URL and then retrieve the data. The data we get back will be a string, so we can use python's json library to convert the string into a dictionary of the data!
To do most of this plumbing we are providing getDataFromURL(base_url, params) that will take in the base URL as well as a dictionary of parameters you want and returns the data. It is here.