Understanding APIs… Everything you need to know about APIs

Mohammed Rishard
Star Gazers
Published in
7 min readApr 4, 2021

--

What is an API?

API stands for Application Programming Interface. It is a set of programming code that allows data transmission between multiple applications. For example, when you use an application the application can send data to the server, the server then retrieves the data, interprets it, performs the necessary operation and send it back to the client which is the application. The application then interprets the data and present it in a readable format to the client. All of this process happens via API. Simply API is the messenger that takes the requests and tells the system what you want to do and then returns the response to you.

If you still can’t understand what is an API let me explain a familiar example. Imagine that you have gone to a restaurant and you need to order some foods on the menu card. How will you order? Do you directly go to the kitchen and prepare your food? No, isn’t it? You order it through the waiter. The waiter will write down your order and will inform it to the kitchen and after the food is ready the waiter will serve you the food. So API is similar to the waiter, that takes your request and tells the server( Here it is the Kitchen) what to do and once the request is processed the API delivers the response back to you.

API consists of 2 components :

1. Technical Documentation explaining the options for data sharing between applications.

2. Software Interface coded according to the technical documentation

If software needs to access information from another software, it calls its API by providing the necessary information as mentioned in the technical document. So the other software responds with the information requested. The software calling the API doesn’t need to know the implementation of the server, what it needs is the response, not the implementation and processing of the response. APIs serve as a layer of abstraction for two structures, covering the latter’s complexities and operating information.

Purposes of API

1. APIs makes life easier for developers — Developers can easily add functionality to existing solutions using service by third party providers. They can easily connect their software with another one.

2. APIs control access to resources — APIs play a major role in security. APIs are often used to limit access to hardware devices and software features that an application might not be allowed to use.

3. APIs are used for communication between services — We can use APIs to access many online services from our application. For example, if we need details about the weather for our application we can easily use the Weather API to get information about the weather.

Types of APIs

Based on the release policies APIs can be divided into 3 as :
1. Private
2. Public
3. Partner

Private APIs

These APIs are designed for improving solutions and services within an organization. These APIs are accessible only by the developers who work in the organization. These developers may use these APIs to integrate an organization’s IT systems or applications or create a new system using existing resources. The use of private APIs enables an organization to have total control over how the API is used.

Partner APIs

These APIs are used by business partners who have reached an agreement with the publisher. Software integration between two parties is a common use case. A company offers its partners access to data or functions to accomplish their tasks.

Public APIs

These are external APIs. They are available for third-party developers. These Public APIs can be Free and Commercial. Commercial API users must pay an amount to use the APIs.

Use cases of APIs

  1. Database APIs — These APIs allow communication between an application and a database management system.

2. Operating System APIs — This collection of APIs specifies how programs interact with operating system tools and services. Every operating system has its own series of APIs, such as the Windows API or the Linux API. These APIs allow developers to develop applications using the resources and services of the Operating system.

3. Remote APIs — Remote APIs allow developers to communicate with remote services using protocols, which are communication specifications that allow various technologies to communicate with one another regardless of language or platform. These APIs describe interaction requirements for applications that operate on various devices. Two examples of remote application programming interfaces are the Java Database Connectivity API and the Java Remote Method Invocation API.

4. Web APIs — This is the most common use case of APIs. Developers use these Web APIs to increase the functionality of their applications. These APIs represent Client-Server architecture. These APIs predominantly use Hypertext Transfer Protocol to deliver requests from web applications and responses from servers.

API Specifications

At present, there are many programming languages, operating systems and technologies. The number of programming languages and frameworks increase day by day. It is not possible for a developer to know all these languages. Therefore in order to handle the API requests and response, there should be some specifications or protocols. These API specifications provide the ability for diverse systems to seamlessly communicate with each other.

There are 4 main protocols. They are :

1. Remote Procedure Calls (RPC)
2. Service Object Access Protocol (SOAP)
3. Representational State Transfer Protocol (REST)
4. GraphQL

1. Remote Procedure Calls (RPC)

It has a straight forward interaction between a client and a server. The client remotely calls a method in the server and the server executes the method.

2. Service Object Access Protocol (SOAP)

SOAP is a simple protocol for sharing structured data in a distributed, decentralized environment. It enables XML messaging between systems through HTTP. SOAP is most widely used in corporate web-based applications to guarantee the security of data. Payment gateways, identity protection, and CRM solutions, as well as financial and telecommunication services, all prefer SOAP APIs.

3. Representational State Transfer (REST)

REST is a software architecture style that has six constraints for creating HTTP-based programs, such as web services.

If you need to know more information regarding the REST constraints please read the below article.
https://rishard-akram.medium.com/understanding-rest-7dc9e829da9d

REST is seen as a more user-friendly alternative to SOAP, which many developers find challenging to use because it necessitates writing a lot of code to complete each mission and adhering to an XML format for each message received. REST makes data available as resources. Each resource has a unique URI and one can use this resource by specifying the URL. These resources can be modified by using the HTTP verbs such as GET to retrieve information, PATCH to update information, POST to insert data and DELETE to delete the resource.

One of the reasons REST is a popular option for creating public APIs these days is its ability to accommodate several data formats for storage and exchange. RESTful systems can send messages in a range of formats, including plain text, Javascript, YAML, XML, and JSON, while SOAP can only send messages in XML.

REST is schemaless and the server decides how the data is returned, therefore we can’t retrieve only certain information from the resources. When we request information from a resource we get every detail about the resource and we have to filter the response and get the required information. For example, assume that we need only the full name of the user but using REST you can’t get only the name what you can get is every detail of the user and then you will have to filter out the name. So if the resource is very huge it can increase the response time unnecessarily.

4. GraphQL

It has a schema and the client decides how the data is returned which means that the client can retrieve only the required data. GraphQL is initially created by Facebook for its internal use and it has a more efficient data loading due to increased mobile adoption. GraphQL is an API query language. It enables the client to choose the exact data it requires and simplifies data aggregation from various sources, allowing the developer to make only one API call to obtain all of the information required.

Apps using GraphQL control what data they need to fetch from a server, which allows them to run fast even when the mobile connection is slow.

Please follow me and stay tuned to get to know how to create REST APIs using Koa.js

--

--