Demonstration of the gRPC protocol with a Go server and a Flutter client.
gRPC is an alternative to HTTP-JSON which sends structured binary data over HTTP/2 instead of plaintext JSON, resulting in performance increases and more portable models. This is accomplished through the use of Protocol Buffers for model development.
To start the server:
docker-compose up
This will launch the gRPC server as well as the Envoy proxy required to run the demo on Flutter Web (explained below).
To start the client:
cd client && flutter run
In order to run the Flutter demo on a device (instead of a simulator), you must use ngrok to tunnel the TCP traffic (requires a free ngrok account).
ngrok tcp 50051
After running this command, you'll need to copy the Forwarding
address to client/lib/core/config/config.dart (lines 13 and 24). For Flutter Web, the port is always 8080
because its traffic is routed through the Envoy proxy.
In order to use gRPC on the web, the grpc-web library is used. Currently, only unary and server-side streaming are supported. Moreover, an intermediate proxy is required to convert HTTP/2 requests and responses to HTTP/1 for the browser. For more information, see this blog post.