Basics of API and API Protocols
API (Application Programming Interface )
API or Application Programming Interface is a bridge or a messenger between two applications that help communicate between the two.
Improves workflow within a company as API enables the integration and collaboration of different applications and platforms seamlessly
API provides security by creating an additional layer of protection between client and server.
API helps in innovation and generation of earning opportunities as it makes the communication between different platforms and applications globally.
Functioning of API
The client application generates a request/call to retrieve information. The request is processed by API's Uniform Resource Identifier (URI) which includes a request verb, header, and sometimes body.
After the request API makes a call to the server.
The server generates an appropriate response to the request and sends it back to API.
API shares the data with the client application.
A protocol is a set of defined rules which specifies the accepted data types and commands. Protocols help in standardized data exchange between the two applications.
Types of API Protocols
SOAP (Simple Object Access Protocol) :
SOAP is an official protocol or set of defined rules which is maintained by the world wide web consortium. SOAP is a built-in XML that helps users to send and receive data through SMTP (Simple Mail Transfer Protocol) and HTTP (HyperText Transfer Protocol). SOAP was developed as an intermediate language so that applications built on various programming languages could talk easily to each other. SOAP contains Envelop, Header, and Body in it.
REST (Representational State Transfer) :
REST is a set of architectural principles/ constraints which allows developers to implement REST in a variety of ways. REST is not an official protocol but recommended set of principles. The basic structure of REST contains Client-server architecture, Stateless client-server communication i.e. no client content is stored on the server between requests, Cacheable data (to avoid direct client-server interaction), Uniform interface (to transfer uniform information in a standardized form), layered system constraint where client-server interactions can be mediated in the hierarchy, and code on demand which allow servers to extend the functionality of clients by transferring executable code.
RPC (Remote Procedural Call)
Remote Procedure Call (RPC) is a protocol that provides the high-level communications paradigm used in the operating system. The RPC protocol enables users to work with remote procedures smoothly. The remote procedure calls are defined through routines contained in the RPC protocol. Each call message is matched with a reply message.
SOAP vs REST
SOAP is an official protocol that is maintained by the World wide web consortium.
REST is a set of principles that is not official but recommended
SOAP is slow as it requires more coding according to a defined set of rules
REST is a faster alternative in web-based scenarios and is more scalable.
SOAP is a protocol with specific requirements like XML messaging
REST offers flexible implementation to developers
SOAP web services offer built-in security and transaction compliance which aligns with many enterprise needs, but that also makes it heavier
REST API is lightweight, which makes it ideal for newer contexts like mobile app development internet of things, and serverless computing.
Amazon uses SOAP based API as well as REST based APIs
Google, Twitter, and Facebook use REST based APIs