We are surrounded by software and applications. Our life, day by day, is related in some way to a set of computer programs. These programs have the ability to communicate with each other, how can they do it? Well because they expose an API, or Application Programming Interface.
Before talking about API’s in software, let’s see an example that exists today in your home. A plug, or power outlet. Have you noticed that in the same socket where you can connect a laptop, you can also connect a microwave, a toaster, a refrigerator, a hair dryer, and even the charger of your cell phone? The reason for this is that the plug acts as an interface that allows current to flow to any device connected to it. The powerful thing about this is that any electrical device can use the plug. Therefore, a set of devices can use the same resource to operate. In our analogy, the plug has been the API, and the devices are the clients of the API.
Returning to the world of web development, an API, or specifically, a Web API, is a set of defined interfaces which allow a set of external applications to consume the software of the web application. In more practical terms, a web API exposes a set of functions of a web application which can be consumed by desktop applications, mobile applications, and even other web applications. Although, a Web API can be more than a set of simple functions exposed, as we will see in a future post.
An API allows two completely different applications to communicate with each other. An Android application made in Kotlin can communicate with a web application made with C# through an API.
Another importance of the APIs, at a general level, is to allow abstractions. The idea of an abstraction is that it allows us to facilitate the use of a software without needing to know how it works internally, it is enough to use the functions that the API exposes. Returning to the example of the plug, you do not have to be an electrical engineer or know how electric physics works to connect a toaster to the plug, just use the “API” to consume it.
A Web API can be seen as a set of functions of our web application, which can be consumed by other applications at a distance. We are focusing on Web API’s here, but API’s, in general, refers to the idea that given an interface, two entities can communicate with each other, without the need of knowing obscure details about the other.