Extreme API with Python

Table Of Contents
Extreme API with Python
Page | 27
Part no.9036931-00 Rev AA February 2021
In the response window, you can see the HTTP Status code, in this case an encouraging 200, and the
data sent back in JSON by the API. You can now use this information in the application, as you can see
the keys and value types returned.
You can now write a Python application to interface with this API.
import requests
headers = {"Accept": "application/json"}
try:
r = requests.get('HTTPS://icanhazdadjoke.com/', headers=headers, timeout=3)
except requests.exceptions.Timeout:
print("Service is currently unavailable, please try again later")
exit(0)
if r.ok:
joke = r.json()
print(joke["joke"])
else:
print("No joke today!")
You can now access the joke for the day:
I am so good at sleeping I can do it with my eyes closed!
2.7 Webhooks
When dealing with APIs, it is sometimes more practical to rely on webhook services than making REST
CALLs. Webhooks are sometimes referred to as reverse API, as they push data automatically from a
service to an application, instead of having the application request data. This approach can be more
elegant when you want to update data as it changes, and this can also be a better way to interact with
an official API, as it can potentially limit your number of CALLs per day.
There are several sites to help you test webhooks, such as the Webhook.site
.