@ Julian Reshke made good points. The web is document-based, if you want your application to play on the WWW ... it must comply with the rules of the game.
However, you can create WS-based WS applications that meet these requirements.
But you still want to use HTTP for some other things, such as getting resources or views and caching them using HTTP caching mechanisms. For example, if you have a large application, you want some large views to load on demand, rather than packaging everything in a large main view.
It would be painful to implement your own caching mechanism for HTML to get views and cache them in local storage, for example. In addition, using traditional HTTP requests, these views can be cached in CDN and other proxy caches.
Websockets are great for supporting βconnectedβ semantics, sending data with a slight delay, and pushing data from the server at any time. But a traditional HTTP request is still better suited for operations that can benefit from distribution mechanisms such as caching, CDN, and load balancing.
About the REST API and the WebSocket API (I think your question was actually about that), this is more convenience than preference. If your API has a higher connection call speed ... a website probably makes more sense. If your API receives a low call speed, it makes no sense to use WebSocket. Remember that a connection to Websocket, although it is lightweight, means that something is being held on the server (that is: the state of the connection), and this can be a waste of resources if the speed of the request does not justify it.
source share