How to bring a gRPC defined API to the web browser

前端 未结 8 836
孤街浪徒
孤街浪徒 2021-01-29 22:39

We want to build a Javascript/HTML gui for our gRPC-microservices. Since gRPC is not supported on the browser side, we thought of using web-sockets to connect to a node.js serve

8条回答
  •  轮回少年
    2021-01-29 23:17

    I see a lot of answers didn't point to a bidirectional solution over WebSocket, as the OP asked for browser support.

    You may use JSON-RPC instead of gRPC, to get a bidirectional RPC over WebSocket, which supports a lot more, including WebRTC (browser to browser).

    I guess it could be modified to support gRPC if you really need this type of serialization.

    However, for browser tab to browser tab, request objects are not serializsed and are transfered natively, and the same with NodeJS cluster or thread workers, which offers a lot more performance.

    Also, you can transfer "pointers" to SharedArrayBuffer, instead of serializing through the gRPC format.

    JSON serialization and deserialization in V8 is also unbeatable.

    https://github.com/bigstepinc/jsonrpc-bidirectional

提交回复
热议问题