Based on | REST is mainly based on CRUD operation. | WebSocket is low-level protocol which is based on concept of socket and port which are underlying transport mechanism. |
HTTP | HTTP is one of the common protocol in RESTful web services. | Here use of HTTP occurs in initial connection. |
Direction | REST is Uni-directional in nature. | Where as WebSocket is Bi-directional in nature. |
State | As we knows REST is based on HTTP which is stateless protocol. | WebSocket is stateful protocol. |
Nature | REST is mainly based on resource rather than commands. | This have Socket-based concept. |
Cost | When we say about COST REST based communication is comparatively higher in cost. | WebSocket communication cost is lower. |
Client Server approach | When we say about REST base approach either client is talking to client or server is talking to the client at any given time. | In WebSocket communication allows the client and server to talk independently of each other. |
Performance | Great for occasional communication or we can say for an HTTP request, a new TCP connection is initiated. | WebSocket works better, where the client-server communicates over the same TCP connection for the life of web socket connection or we can say better with high loads. |
Live Example | REST is better fitted for occasional communication in a typical GET request scenario to call RESTful APIs. | As we knows that it is ideal for scenrio where we have high loads just like real-time scalable chat application is an example. |
Scale | REST is HTTP based which can scale horizontally. | WebSocket connection can scale vertically on single server. |
Best for | REST is better suited for the scenario with lots of getting request. | WebSocket approach is always ideal for real-time scalable application. |
Use of | RESTful application needs to design operation based on verbs and HTTP based.
| WebSocket requires the use of IP address and Port details, which are lower-level details for any application. |