Websocket API to replace REST API?

后端 未结 10 1685
温柔的废话
温柔的废话 2020-12-02 03:43

I have an application whose primary function works in real time, through websockets or long polling.

However, most of the site is written in a RESTful fashion, which

10条回答
  •  感情败类
    2020-12-02 04:05

    I'm thinking about transitioning to a WebSocket api for all site functions

    No. You should not do it. There is no harm if you support both models. Use REST for one way communication/simple requests & WebSocket for two way communication especially when server want to send real time notification.

    WebSocket is a more efficient protocol than RESTful HTTP but still RESTful HTTP scores over WebSocket in below areas.

    1. Create/Update/Delete resources have been defined well for HTTP. You have to implement these operations at low level for WebSockets.

    2. WebSocket connections scale vertically on a single server where as HTTP connections scale horizontally. There are some proprietary non standards-based solutions for WebSocket horizontal scaling .

    3. HTTP comes with a lot of good features such as caching, routing, multiplexing, gzipping etc. These have to built on top of Websocket if you chose Websocket.

    4. Search engine optimizations works well for HTTP URLs.

    5. All Proxy, DNS, firewalls are not yet fully aware of WebSocket traffic. They allow port 80 but might restrict traffic by snooping on it first.

    6. Security with WebSocket is all-or-nothing approach.

    Have a look at this article for more details.

提交回复
热议问题