API (Application Programming Interface)
API stands for Application Programming Interface. It is an interface which allows two applications to talk to each other without having to know how they are implemented. It defines the type of calls, methods to make them, data formats to be used, the conventions to follow etc. The application that requires information from another application, calls an API while specifying the requirements of how the retrieved data must be presented. The responding application provides the data in the requested manner.
Image from https://www.altexsoft.com
APIs can be classified by the systems for which they are designed:
· Database APIs - enables communication between an application and a database
· Operating Systems APIs - defines how applications use the resources of operating systems.
· Remote APIs – defines standards of communication between applications running on different machines
· Web APIs - provides data and functionality transfer between web based systems which represent client-server architecture.
Benefits of API :
· Provides flexibility
· Simplifies design
· Provides opportunities for innovation
· Saves time and money
API Architecture and Protocols
A protocol specification was developed to help standardize the exchange of information. Different API architectures specify different protocols.
SOAP (Simple Object Access Protocol) is a protocol that uses XML as a format to transfer data through HTTP or SMTP. SOAP makes it easier for apps running in different environments or written in different languages to share information. SOAP is mostly used with enterprise web-based software to ensure high security of transmitted data. They are usually preferred among providers of fateways, identity management and CRM solutions as well as financial and telecommunication services.
REST (Representational state transfer) is considered a simple alternative to SOAP APIs. Unlike SOAP APIs which involves a lot of coding and XML structures, REST makes data available through resources. Each resource is represented by a unique URL. The web APIs that compy with REST architectural constraints are called RESTFUL APIs. They use HTTP requests to work with resources : GET, PUT, HEAD, POST, PATCH, CONNECT, TRACE, OPTIONS and DELETE. Among data formats like HTML, YAML, XML etc, JSON is used predominantly. For an API to be RESTFUL, it must adhere to the following constraints:
· Stateless – these APIs do not allow the server to retain the information they receive from the client/sender
· Uniform Interface – The client and server should communicate with one another through HTTP(Hyper Text Transfer Protocol) using URIs(Unique Resource Idetifiers), CRUD(Create, Read, Update and Delete) and JSON(Java Script Object Notification) conventions.
· Cacheability - Caching can eliminate the need of client-server interactions
· Layered system – uses different architecture layers. These layers could offer additional features like load balancing, shared caches or security.
Here are few difference between SOAP and REST APIs
Function: SOAP is function driven while REST is Data driven.
Data Format: SOAP is XML while REST uses a range of data formats including XML and HTML, JSON etc.
Security: SOAP uses WS-SECURITY and SSL encryption. REST supports https and SSL.
Bandwidth: SOAP requires more resources and bandwidth while REST is completely light weight with fewer resources.
Data Cache: REST can be cached but SOAP cannot.
For the most part, when it comes to APIs for web services, developers tend toward a RESTful architecture unless the SOAP is clearly a better choice, say for an enterprise app that’s backed by more resources, needs super tight security, and has more requirements.