API Calls
Last updated
Last updated
It's a "contract" that defines how separate software interacts with each other.
GET - get data (what are the available timings tomorrow)
POST - creating or inserting new data (making a lunch reservation)
PUT - update existing data (updating the timing for a lunch reservation)
DELETE - deletes data (removing your lunch reservation)
First, we import an external library that helps us make API calls
Next, we will query an API of your choice.
Google the API you are looking for (e.g. searching "random cat facts API" )
We will then make use of this API: https://catfact.ninja/
To obtain a random fact, we call .get
on /fact
When running this, you should get <Response [200]>
.
A status code of 200 means the API call was successful.
Let's call the data we received
We should get a random fact about cats in a dictionary
API responses are typically encoded as JSON (JavaScript Object Notation). For us to use it in python, we can call the .json()
method to convert it into a dictionary.
Call the fact and print the String
Finding the parking lots available at a carpark
Description of the API can be found here
This sends a query to the API to obtain the carpark availability
Retreives the number number of carparks with data