API
API stands for Application Programming Interface. What it essentially means is a way to communicate with a system or application (software) to do certain operation without using the default interface provided by that application of system.
In terms of computer and network we will call then the set or rules and protocols that allows different software applications to communicate with each other.
To communicate with and application or use the provided API you should first know the rules and regulations set for use with the API as well as the format in which the data is sent or received to and fro the API.
To understand the concept of an API the most common example that is used and suits best from real life is a "Restaurant".
When you go to a restaurant you know that you want to have food or drinks. Consider the restaurant ans a complete system that will provide you the food you order.
Let us look how this works.
- You go to a suitable restaurant.
- You give a call to the waiter.
- Here our "Waiter" is the connection between us and the back end section say the kitchen.
- The "Waiter" will be taking all our orders and responding to us based on our requests.
- The "Waiter" here acts as an API.
- The first request that you give the waiter is for the "Menu"
- The waiter responds with a "Menu Card" or some time will just read out the possibilities available.
- Based on you selection you will again give you order to the waiter.
- Waiter will take this order to the kitchen and ask the "cooks" (internal processes) to make the required dishes.
- The waiter then brings back these dishes and server them to you.
- Note that you are not allowed in the kitchen of the "Restaurant" you can only send order and receive appropriate results based on you requests to the waiter.
- So the only way to access this application is via the API.
- A similar process happens in software applications where you can do the "Create Retrieve Update and Delete" operation via the API.
Now consider the kitchen in you home. You can have a cook available with you and ask the cook to make you required dishes. In this scenario you are using the kitchen system via an API.
But here you can also go to the kitchen and prepare the dishes you want, in this case you are using the application from the main interface.
In real world scenario also we have applications that can either be accessed via API or there main interface. The most common example of this is a Decoupled CMS.
Key Components of an API:
Endpoints:
These are the URLs or URIs (Uniform Resource Identifiers) that the API exposes. Each endpoint represents a specific functionality or resource provided by the API.
Request Methods:
APIs support various request methods, such as GET, POST, PUT, DELETE, etc., which determine the type of operation being performed on a resource.
Parameters:
Additional pieces of information that can be sent along with a request to specify the desired behavior or to filter the results. Parameters can be included in the URL (query parameters) or in the request body.
Response:
When a client application sends a request to an API, the API processes the request and returns a response. The response typically includes the requested data or confirms that the requested action was completed successfully.
Types of APIs
Based on the design and accessibility of the API they are classified into the following:
Web APIs:
APIs that are accessed over the internet are called Web API. These are usually accessed via protocols HTTP/HTTPS etc.
These API are generally RESTful, REST stands for representational state transfer and was created by computer scientist Roy Fielding.
RESTful means they stick to the principles of Representational State Transfer, and use HTTP methods like GET, POST, PUT, and DELETE to perform CRUD operations on resources.
Library APIs:
These are APIs provided by software libraries or frameworks that developers can use to access the functionality provided by those libraries. Library APIs are typically used within the same programming language and are called through function or method calls.
Operating System APIs:
These are APIs provided by operating systems to allow applications to interact with various system resources such as file systems, devices, network interfaces, etc.
Based on the accessibility of API they can also be classified a Open or Private API.
Open or Public API:
open API is a publicly available application programming interface that provides developers with programmatic access to a software application or web service.
Private API:
A private API is an interface that opens parts of an organization's back end data and application functionality for use by developers working within that organization.
Paid API:
These are API's that any one can access but to use the API service you will need to pay for it. Generally a token is provided to use these API.
Examples of API
Google Maps API:
The API allows developers to integrate maps and location-based services into their applications. Developers can embed maps, display route information, search for places, and more.
Twitter API:
Twitter API enables developers to access Twitter's data and functionalities, such as fetching tweets, posting tweets, searching for tweets, and managing user accounts.
OpenWeatherMap API:
OpenWeatherMap API offers weather data and forecasts for locations worldwide. Developers can retrieve current weather ditions, forecasts, historical weather data, and more.
The Cat API:
Allows you to accesses cat images via API.