How to make an API call with just 3 lines of code!

Andrew Alteri
2 min readJul 13, 2021
API — Application Programming Interface

An API (Application Programming Interface) is part of our everyday life. Whether you are browsing the web, checking you phone apps, playing a game, or streaming a show, you are using an API. So, what exactly is an API? An API is a set of protocols and procedures that allow the interaction between two applications. You can think of it as the technical liaison. The client makes a request to the server, the liaison or API gets the requested data, and then the server responds with some form of data back to the client through the API. A popular analogy would be a waiter at a restaurant. The guest, the client, orders food and gives that order to the waiter, the API. The waiter then takes the order to the cook, the data server, and brings the food order back to the guest when it is ready. This is how APIs work on a high level.

Now that you know how APIs work, let me show you how to make an API call with Python and an API endpoint**:

Here we have three easy steps:

*(Make sure Python is installed on your computer.)

1) import requests (after $ python -m pip install requests)

2) Use requests to make a get request for an API. Here I make a request to find out the next MCU movie/show and how many days until it’s premiere. (Get is part of the CRUD operations. You use get when you want to literally get some information.)

3) Print the response in the terminal in an easy-to-read JSON format.

That is all you need to make an API call with Python! Now go out and have fun with some APIs!

**(An endpoint is basically a URL for a server or service. The endpoint is the way the API can access the resources it needs from a server so it can perform its task.)

--

--