Table of contents
The world of software relies on the ability of different applications and software to interact with each other by sharing data and communicating. This communication is typically done through APIs (Application Programming Interfaces).
In this article, we will take a close look at what an API is and how they enable developers to effectively and efficiently build software.
Understanding APIs
Most applications in this day and age are data-driven, relying heavily on data from multiple services. These services are typically separate and manage isolated data sets specific to the context of that service. What happens, however, when a service needs to retrieve data or perform an action that is outside its own context?
As a basic example, consider a multi-tier application with a:
- Frontend application
- Backend application
- Database
What happens when the frontend application's interface allows you to add data to your database? For security reasons, the frontend application should not have direct access to the database, so how would you go about creating that data?
In this example, the backend application may provide an API that exposes operations that allow you to perform CRUD (create, read, update, delete) operations on your database.
The API's role
The way these operations are exposed may vary depending on the type of API the backend application provides, however in general an API will expose some set functions or endpoints that allow you to perform pre-defined sets of operations.
These pre-defined operations act as "contracts" between the two services. For any given operation, you should be able to request its invocation and expect some sort of response back. Often, you will provide data via a request body or URL variable and expect a JSON response back, however, this varies based on the flavor of API you are working with.
We won't cover the various types of APIs in this article, however, to name a few there are:
- REST
- GraphQL
- gRPC
- SOAP
The common factor between all of these and the important takeaway of this section is:
APIs are software intermediaries that allow two services to communicate with each other by passing data to and from each other.
Benefits of using APIs
Without APIs, there would be no such thing as third-party services such as Stripe and Mailchimp, and front-end applications would have no way to communicate with a server.
Every application or website you use is likely communicating with some sort of API. This is why APIs are such a powerful concept. Rather than re-inventing the wheel when adding things like payments, email services, mapping data, etc... APIs allow you to re-use existing functionality simply and consistently.
APIs allow you to consistently re-use functionality without re-inventing the wheel.
Conclusion
To recap, APIs allow applications and software to communicate with each other using pre-defined, repeatable actions exposed by the API.
APIs are commonly provided by service providers to give you access to easily implement payments, email services, and much more. Along with this, essentially any multi-tier application will need to make use of some sort of custom API to allow client-side applications to interact with data from a database.