Difference between Rest API and Web Socket API
In IoT, there are 2 communication APIs –
- REST Based Communication APIs
- Web Socket Based Communication APIs
Web service can either be implemented using REST principles or using Web Socket Protocol –
1. REST Based Communication API :
REpresentational State Transfer (REST) is a set of architectural principles by which you can design web services and web APIs that focus on a system’s resources and how resource states are addressed and transferred. REST APIs follow the request-response communication model. The REST architectural constraints apply to the components, connectors, and data elements, within a distributed hypermedia system.
2. Web Socket Based Communication APIs :
Web Socket APIs allow bi-directional, full-duplex communication between clients and servers. It follows the exclusive pair communication model. This Communication API does not require a new connection to be set up for each message to be sent between clients and servers. Once the connection is set up the messages can be sent and received continuously without any interruption. WebSocket APIs are suitable for IoT Applications with low latency or high throughput requirements.
Difference between Rest API and Web Socket API :
|S.NO.||REST API||WEB SOCKET API|
|1.||It is Stateless protocol. It will not store the data.||It is Stateful protocol. It will store the data.|
|2.||It is Uni-directional. Only either server or client will communicate.||It is Bi-directional. Messages can be received or sent by both server or client.|
|3.||It is Request-response model.||It is Full duplex model.|
|4.||HTTP request contains headers like head section, title section.||It is suitable for real-time applications. It does not have any overhead.|
|5.||New TCP connection will be set up for each HTTP request.||Only Single TCP connection.|
|6.||Both horizontal and vertical scaling (we can add many resources and number of users both horizontally and vertically).||Only vertical scaling (we can add resources only vertically).|
|7.||It depends upon the HTTP methods to retrieve the data..||It depends upon the IP address and port number to retrieve the data|
|8.||It is slower than web socket regarding the transmission of messages.||web socket transmits messages very fastly than REST API.|
|9.||It does not need memory or buffers to store the data.||It requires memory and buffers to store the data.|
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.