APIs have been revolutionizing the world since the birth of first-generation computers but they were not coded in high-level languages as they are being done today. The APIs are core concepts of programming which every programmer has to learn for achieving working levels of proficiency. As of now, APIs have reached a high level of sophistication which needs to be classified into types of APIs to get a good level of understanding.
What are APIs? Types of APIs
APIs are an acronym for Application Programming Interface which means a set of functions and procedures allowing the creation of applications that access the features or data of other application, service or an operating system.
In layman terms, APIs are pipelines which connect applications these connections are done using the features of another application into the main application, In APIs types of messages, are defined which will be communicated through these APIs.
Read: "What is an API and How it works?"
For example, many websites show the live feed from twitter so they use APIs from twitter on their website to fetch and display the live feed.
Types of APIs
The classification of APIs can be done on three parameters which are listed as follows:
Ownership types of Web APIs
On Ownership level there are four main types of APIs:
-
Open APIs: These APIs are publicly available to use like Oauth APIs from Google and there is no restriction to use them. Hence, they are also known as Public APIs.
-
Partner APIs: Specific rights or licenses in order to access this type of API because they are not available to the public. Usually, these kinds of APIs are associated with paid services.
-
Internal APIs: The APIs that are developed by companies to use into their internal systems so that they can enhance the productivity of development teams where one team can use services from another project of the company is called Internal APIs. These APIs are also known as Private APIs.
-
Composite APIs: Both processes and composite APIS are a sequence of tasks but composite APIs combines different data and service APIs. It is a sequence of tasks that run synchronously as a result of the execution where the result of triggering of a Composite API is the result of the execution and not the request that will contain the result of the execution at the request of a task. Its main usage is to speed up the process of execution and improve the performance of the listeners in the web interfaces.
Communication level of APIs
-
High-Level APIs
High-level APIs are those that we use generally in REST form where programmers have a high level of abstraction and they are only concerned about performing a limited functionality.
-
Low-Level APIs
Low-level APIs have a lower level of abstraction hence they are most detailed, which allows the programmer to manipulate functions within an application module or within hardware at a granular level. Usually, Low-level APIs are used in sending the real-time video or media feed in response to a trigger like Vulkan APIs.
Web service APIs
In web service APIs the classification is done on the type of communication and behavioural approach used in building APIs:
-
SOAP
-
XML-RPC
-
JSON-RPC
-
REST
Web service APIs are small applications that use URLs or web addresses on the internet to provide their services to desktop, mobile, web applications and others.
-
SOAP
SOAP (Simple Object Access Protocol) APIs are more complex than its peers. These APIs have their own communication protocol called Simple Object Access Protocol which makes them a bit more defining than REST in terms of the level of security and the approach to how messages are sent. SOAP offers comprehensive security, built-in ACID (Atomicity, Consistency, Isolation, Durability) compliance and retry logic for reliable messaging functionality which makes it a more suitable for enterprise application which deals with banking transactions, LDAP interaction and more.
Read: "Monolithic vs Microservice Architecture- Pros and Cons"
SOAP is a standardized protocol which uses only proprietary XML format for transferring structured information that’s more function-driven. The APIs are used to send payloads which is data, its type and communication preferences. Since SOAP uses XML to send payloads hence it requires more bandwidth. In addition to SSL support SOAP uses WS-Security, which is great at the transport level and a bit more comprehensive than SSL. Due high level of security SOAP-based calls cannot be cached. SOAP is closely coupled with the server, having a strict communication contract with it which makes it more difficult to make changes or updates. Interacting with a SOAP API needs knowledge about everything even before you can even initiate an interaction.
Read: "Top Web Development Technologies and Frameworks"
SOAP has built-in ACID compliance which reduces anomalies and protects the integrity of a database by prescribing exactly how transactions can interact with the database. ACID is much better than data consistency models. ACID is used in structural databases like Oracle’s SQL database to deal with banking transactions and inventory management in behemothic eCommerce platforms.
SOAP has successful/retry logic built-in and provides end-to-end reliability through SOAP intermediaries.
The use case where you want to use SOAP API in building an application is only the desire to achieve a high level of security.
-
XML-RPC
XML-RPC (Extensible markup language – Remote Procedure Calls) is a protocol that uses a specific XML format to transfer data. XML-RPC uses minimum bandwidth and is much simpler and older than SOAP.
-
JSON-RPC
JSON-RPC (JavaScript Object Notation) is a protocol which uses JSON format to transfer data. The RPC calls are one of the methods that are used by services to communicate in a microservice architecture.
-
REST
REST (Representational State Transfer) is a more data-driven architectural style that we use in building REST APIs. REST APIs are based on URIs (Uniform Resource Identifier) HTTP protocol, and the use of JSON for a data format, which is super browser-compatible. REST APIs can be simple to build and scale as compared to other types of APIs.
-
REST APIs facilitates client-server communication with simplicity.
-
REST APIs uses SSL security which means it can use HTTPS.
-
REST APIs uses different data formats including plain text, HTML, XML, and JSON sending payload which is a great fit for data and yields more browser compatibility.
-
The usage of simpler data formats makes the payloads lighter which makes REST APIs be a better fit for a broader range of applications.
-
REST APIs use a single uniform interface. This simplifies how applications interact with the API by requiring they all interface in the same way, through the same portal. This has advantages and disadvantages.
-
REST calls can be cached.
-
REST APIs are best for reliability and scalability.
The reasons why you may want to build an API to be RESTful because it includes resource limitations, fewer security requirements, browser client compatibility, discoverability, data health, and scalability.
Read: "What is Serverless Web Application Development?"
Here’s some bonus info for reading the whole article
What does stateless mean in REST?
In REST (Representational “State” Transfer) architecture it is defined that the server does not store any state about the client session on the server-side. This restriction is called Statelessness. Each request from the client to server must contain all of the information necessary to understand the request and it cannot take advantage of any stored context on the server. The Session state is therefore kept entirely on the client. The client is responsible for storing and handling all application state-related information on client-side. It also means that the client is responsible for sending any state information to the server whenever it is needed. So, there should not be any session affinity or sticky sessions on the server.