API Protocol defines the standard on how API will communicate with internet / other systems and on how the information is transferred.

The single API can be implemented with multiple protocols. API protocols can transfer any type of data. There are different API protocol types. Let’s look at commonly used API protocol types

SOAP (Simple Objects Access Protocol)

This is the older API protocol which was emerged in 1998. This is also the simplest form of API. This uses XML files to transfer the data between two services over HTTP or HTTPS connection. It can also transfer data on other connections like SMTP ( Simple Mail Transfer Protocol ), TCP ( Transmission Control Protocol ), UDP ( User Data Protocol ).

SOAP will follow below format

  • Envelope: It envelopes the complete message by placing tags at the beginning and the end
  • Header ( Optional ): It contains the addition information which are needed to process the data. Example : Authentication
  • Body: This is the actual message ( request / response )
  • Fault ( Optional ): Defines all the errors that may arise in the data during execution of API or response.

XML is very difficult to debug, if there is any issue. Because of which, it is less popular in the recent days.

REST ( Representational State Transfer )

This is the best known API protocol which was introduced in 2000. This can transmits data in various formats like JSON, HTML, Python, Media and plain text. REST can only use HTTP or HTTPS to data transmission ( This is one of the limitation ).

REST key components

  • HTTP Method : There are pre defined methods like GET ( fetch data ), POST ( create data ), PUT ( update data ), DELETE ( delete data )
  • End Point : The location to which data is requested from or sent to. URL ( Uniform Resource Locator )is most commonly used for this
  • Header : This will contain information about the data like content type, originating source etc.. It can also contains token / api key which is used for authentication purpose
  • Body : This will be the actual data sent by the service.

REST is more flexible , lightweight compared to SOAP. One of the key feature of RESTFul APIs is stateless communication.

The combination of End Point + HTTP Method is unique and this determines a particular operation.

Google Remote Procedure Call ( gRPC )

While a RESTFul Api returns a document, gRPC service response is the confirmation that procedure / method / function was triggered or an error indicating why it failed to run. gRPC is developed by google and released for public use in 2015.

The gRPC transportation layer primarily relies on HTTP and data is transmitted in protocol buffers which is a language agnostic mechanism.

JavaScript Object Notation–Remote Procedure Call (JSON-RPC)

JSON-RPC is stateless and lightweight API protocol which leverages JavaScript Object Notation (JSON). It was introduced in the early 2000’s which works extensively with JSON to provide straightforward implementation of API communication.

GraphQL

This was release in 2015 by Facebook. GraphQL stands for Graph Query Language, this queries data from server similar to SQL. We define the data we need and as well as the format in the query, GraphQL returns the data in the requested format.

This saves time and memory as only the requested data is queried from the server.

Developer need to chose one among the available API protocol types based use cases being addressed. Each of API protocol types have their own advantages and disadvantages.

Join me at Medium to check on more relevant posts

By Admin