APIs ....Covering the basics

Up until a couple of months ago, I’ve always found the concept of APIs a bit confusing and not straightforward. As I started studying and interacting with them, it became so clear that it would be a shame if I don’t share my discovery.

The very first question one is most likely to ask is What is an API?

API stands for Application Programming Interface. Simply put, a set of programming rules that enables and defines the interaction of two or more application to achieve a predefined purpose ie. it is a program that acts as an interface between applications.

I know you would be asking, “when can I use an API?”

The truth is you probably have used some sort of an API in your life. Ok, maybe not a set of programming codes. If you look at your daily life you, you would have experienced having some kind of interface that helps you get things done. Let me share some basic API Analogy that would give you an idea of what we are talking about.

Imagine the scenarios where you had to walk into a bank to open an account. You approach an officer and lay your request. Then, you are given a form to fill and you are guided through the process. You are done and they confirm that the account is active or when it would be active.

Now think of every other service you would need from the bank that you were assisted with by an officer. Extend the thought to every other thing you have done that always requires some middleman to get it done. That’s how an API works.

I know you would be wondering, do I always need an API?

In most real-life scenarios similar to the Bank instances you do because it has been designed so. However, there are still instances where it’s not and it’s left for you to decide how to interact with the service you want. If you need to interact with a private service, a communication interface would be needed otherwise it could be termed self-service like the vending machines.

Bringing this concept back to the main idea, how do we understand API in terms of programs? Why do we have APIs?

APIs enables data communication between two or more software or applications. Enables developers to build and integrate applications faster and scale quickly. Imagine you are accounted with about 3 financial institutions and they all happen to be on the same street. That would be great right? Then imagine you can access their services all from one application? That’s the power of API. Enabling aggregation of services onto a single application to achieve a need for the customer. I’m pretty sure we have experienced such in banking apps; that enables us to gain access to all our bank accounts, food vendor app; connects restaurants to a single application for easy use.

How do APIs work?

Most APIs exist between the application and the web server and creates an abstraction of the webserver i.e it hides away all the high-level parts and only makes available what is needed to access the services needed. The user executes some actions on the application to do something, then the application (such as a website or a mobile app) makes a call for a set of data to display to the user. This call is routed via the API to the webserver to retrieve the requested data which is then displayed for the user. Every time software is used to communicate with another software or server, an API request is being made to get the information needed.

image.pngProcess flow of an API

The concept of the abstraction is that the user doesn’t need to know how the APIs work, just how to interact with the application to perform the tasks needed. Likewise, the application doesn’t need to know how the server works, just how to get the data needed via the API. This is similar to every other service we tend to receive from the banks, restaurant, hotels and so on. You don’t need to know every detail of how they assemble their services, you just need to understand and know how to make requests for what you want from them.