What is an API?
5 min read
Have you ever shopped at a place that promised lower prices, by cutting out the middleman? Although this might make things easier in the real world by not having to deal with that cheesy storefront and high-pressure salesman. But that middleman is actually very important in the computer world. The Wikipedia definition for API goes like this: “ An Application Programming Interface (API) is a set of functions, procedures, methods, or classes used by computer programs to request services from the operating system, software libraries, or any other service providers running on the computer.”
But Anyone hardly can understand this right?
So, let’s dive deep into this:
What Actually is an API:
Let’s consider software as a club sandwich-like stack of different programs some of which sit between whatever program you’re interacting with directly and the hardware itself. Because without these layers programmers and developers would have to code differently for every single hardware configuration on the planet which would be impossible.
Other layers sit between two different pieces of other software and help them talk to each other without needing to have tons of code in common.
These software layers help standardize the coding process so that programs can interface with lots of different stuff easily and while you might be most familiar with a layer called a Device driver, which translates program instructions and talks directly to your hardware. Another layer called an application programming interface or API can be just as important.
But if a driver is already there then to serve as the link between your hardware and programs then what does the API actually do?
We’ll think of it like this: Windows, Mac OS, and Linux all provide a graphical interface. Your buttons, checkboxes, menus, etc that are easy to click on. Without that, you’d be left tediously typing commands for everything you want to do.
Like back in the days when DOS ruled the world, or if you’re a BASH fan than yesterday, similarly an API provides a simpler way for developers to interact with other kinds of software.
A really good example of this is social media plugins that you see on certain websites. Such as a News article that embeds tweets, or a page that for better or for worse let people leave Facebook comments.
Both Twitter and Facebook have their own APIs that they make available to web developers, making it easy for them to bake Twitter and Facebook features into their own pages.
Without these APIs, these social media giants would have to share code directly with owners of other sites which would be tedious difficult and possibly give away certain trade secrets.
So, I think now that you have got some initial ideas of what an API is, let’s see how this works and functions in the real world.
How API Works?
Previously you read that API makes the life of developers and Enterprises make it easier but how actually they work?
Think API as a messenger how takes your request and tells the system what you want to do and then returns the response back to you.
Like if you want to share this particular in your favorite social media then you just simply click the button. And a popup opens and your message gets shared.
This is not that easy…
When you press the button you are requesting your social media let’s say Facebook to share this particular post. Then An Facebook API Takes your response and delivers it to the Facebook servers.
Then the Facebook servers return with a share this article response and then a popup opens and this article gets shared.
If you still cannot understand How API works then let’s takes another example.
Think you are sitting in a restaurant and you have a menu of choices to order from and the kitchen is the part of the system that will prepare your order and deliver the food back to you. But here’s something missing right?
Yes, the connection between your table and the kitchen. Here comes the waiter or API which makes your life easier by connecting your order to the kitchen and then taking and delivering the food back to your table.
Types of APIs:
Picking the right type of API is very essential for any project. So, let’s see there how many types of APIs and their use cases.
1. Web APIs:
Web APIs or Web-based APIs or Web Services APIs are most commonly used in websites. They are mainly based on hypertext residents Web Services standards like REST, SOAP, XML-RPC, and JSON-RPC.
2. Source-Code APIs:
Source code APIs offer libraries of objects, classes, etc. Source code APIs are often used in development projects to create a composite application. The calls are made according to the standards of the application environment such as J2EE or .NET.
3. Legacy APIs:
A variety of legacy approaches to application interfaces employ flat files, remote object protocols, operating system interfaces, hardware APIs, communication protocols, message queues, and other means.
Referring to these as the legacy is not meant to be a pejorative, but rather a way of grouping a variety of long-standing and established, albeit somewhat older protocols together. A good example of Legacy API is CORBA or Common Object Request Broker Architecture.
I think this article has given you some ideas on what is an API and how it works. If you have felt that this article has helped you then please share it with the world. And if you have any query feel free to let me know in the comments. I reply to every single one.