From the course: Advanced Python: Practical Database Examples

What is an API?

- [Instructor] In this chapter, we'll be creating an API that serves data from a database. API stands for application programming interface. Let's walk through this acronym. The interface is the contract with which two separate programs agree upon to communicate. Let's say Program A, a mobile app, wants to send data to Program B, a backend service for storage. Program A and Program B will agree on a contract or an interface for how that data will be sent and its format. Once the interface is agreed upon, developers write code so that the data is sent in the correct format with the correct communication protocol. It's used in applications, which is where application comes from in API, so they can communicate and transfer data. It's done through programming; hence, application programming interface. An example where an API is commonly used is in the case of data retrieval. Let's say the mobile app wants to display dynamic data like the weather. They'll likely use an API to communicate with a backend service that has access to live weather information in a database. There are different types of APIs that use different protocols, but the most popular of these are REST APIs. With a REST API, the client, in our case, the mobile app, sends requests to the server. The server uses what the client sent to decide what data to return back to the client as a response. Now, you might be wondering why can't the mobile app just have all the data we need within it? It could have a weather database, a database with all the account information, and more. Well, this would make the mobile app very big. It would contain lots of code and it would be hard for several teams to work on at once. The mobile app should be focused on delivering information and visuals to the user, not on how to make data retrieval as efficient as possible. There might also be another system that wants to use the weather information, too, but it might live outside of the mobile app. This is why we often separate components to increase their reusability and decrease the complexity of a single system. In fact, we do this a lot with backend services to create microservices that can be reused for many different applications.

Contents