4. Testing the University Domains API¶
University Domains and Names Data List & API is an API that contains domains, names, and countries of most universities around the world.
Let’s see an example of how to use this API. We will ask for universities in Turkey that have the word “middle” in their name.
Let’s find all the universities in Colombia.
4.1. Learnings¶
We access APIs to search for information that is useful for us.
We can request information with two Python libraries:
urlliborrequests.The
jsonlibrary helps us transform the API’s response into a Python object, either a dictionary or a list, with theloadsmethod, while thedumpsmethod does the opposite; transforms a Python object into a JSON formatted string.The
dumpsmethod ofjsonis useful if we want to visualize the response of an API in a readable way. This is achieved with theindentargument.
-
On a scale from 1 (needs improvement) to 3 (excellent),
how would you rate this chapter?
- 1
- 2
- 3
