IoT APIS are the points of interaction between an IoT device and the internet and/or other elements Within the network. Representational State Transfer (REST) is a set of architectural principles where we can design Web services the Web APIS that focus on the system's resource and how resource states are addressed and transferred.

Iot Communication Apis

REST APIS follows the request-response, communication model. REST architectural constraints apply to the components, connectors, and data elements, within a distributed hypermedia system. A RESTfull web service is a " Web API " implemented using HTTP and REST principles. REST is the most popular lol Communication APIS. The rest architectural constraint is as follows:

Client-server

The function of the client-server constraint is the separation of concerns, for example, clients should not be concerned with the storage of data which is a concern of the server. furthermore, the server should not be concerned about the user interface which is a concern of the client. Separation allows client and server to be independently developed and updated.

Stateless

When a request is sent from client to server. It must contain all the necessary information to understand the request and cannot take advantage of any stored context on the server. The session state is kept entirely on the client.
 

Cache-able

The principle behind the cachable constraint is that the data within a response to a request be implicitly or explicitly leveled as cache-able or non-cache-able. If a response is cacheable, then a client cache is given the right to reuse that response data for later, the same as the request. Caching can partially or completely eliminate some instructions and improve efficiency and scalability.
 

Layered System

The work of layered system constraint is to necessitate the behavior of components in that each component cannot see beyond the immediate layer with which they are interacting. For example, the client cannot tell whether it is connected directly to the end server or two an intermediary along the way. System scalability can be improved by allowing intermediaries to respond to requests instead of the end server, without the client having to do anything different.
 

Uniform Interface

The main aim of the uniform interface constraint is that the communication between client and server must be uniform. Resources are identified in the requests and are themselves separate from the representations of the resource data returned to the client. When a client holds a representation of resources it has all the information required to update or delete the resource. Each message includes sufficient information to explain how to process the message.

Code on Demand

This constraint is the only one that is optional. Servers can provide executable code for clients to execute in their context.

Web Socket Based Communication API 

Web Socket APIS is a full-duplex communication between clients and servers. It allows bi-directional communication, and Web Socket APIS pursues the exclusive pair communication model. Unlike request-response models such as REST, web sockets do not require a new connection to be set up for a cach message to be sent. Web Socket communication starts with a connection setup request sent by the client to the server. The request is sent OVE HTTP and the server interprets it as an upgrade request. If the server supports web socket protocol, the server responds to the Web Socket handshake response. After the connection setup, the client and server can send data/messages to cach other in full-duplex mode. Weh socket API reduces the network traffic and latency as there is no overhead for connection setup and termination requests for each message. Web sockets are suitable for IoT applications that have low latency or high throughput requirements.