The term "API" can be difficult for beginners to grasp, but I am sure it will be clear once you read the following explanation. We will talk about the most popular API approach - the REST API. What is a webpage? A webpage is a document accessible through a URL. A webpage is meant to be accessible by humans. That's why webpages (e.g., the Wikipedia page below) are pleasant to look at. They have good-looking fonts and colors, pictures, etc. Webpages are served by a web app and the web app runs somewhere on a remote server.
On the other hand, we have REST APIs. REST APIs are also apps that run somewhere on a remote server. The difference this time is that a REST API serves data that are meant to be read by computers, not humans. In the example below, we are using a URL from the Wikipedia REST API to get information about dolphins.
I suppose it was easier for you to read the previous webpage than this one. Even though both pages give information about dolphins, the second example is meant to be accessed and consumed by computer programs, not humans. In fact, we can build a computer program that accesses that information right here with Python:
url = "https://en.wikipedia.org/w/api.php?format=json&action=" \
data = requests.get(url).json()
The program above uses the Python requests library, which needs to be installed with "pip install requests" in your terminal. Once you install requests and run the program, you will get the following output:
A dolphin is an aquatic mammal within the infraorder Cetacea. Dolphin species belong to the families Delphinidae (t...
That means your program was able to communicate with the other program (the Wikipedia REST API) and extract information about dolphins. And that is what APIs are about. They provide a communication channel for two programs to communicate with each other. Once your Python program gets access to the info, you can do further operations to that piece of data. You can send it by email via Python, display it on a Flask webpage, and more. The possibilities are endless.
It is also possible to build your own REST API with Python. You will need to use a Python library/web framework such as Flask or Django. Flask and Django are both covered in the course, so don't forget to keep learning.Next Lecture
Learn Flask development and learn to build cool apps with our premium Python course on Udemy.
Subscribe to be the first to know when a new Python course is released.