Announcing official gRPC support for Dart

gRPC is a high performance, open source RPC framework. It offers simple service definitions, is built on http/2, and has support for bi-directional streaming and fully integrated pluggable authentication. The gRPC framework supports a wide range of languages, and we are happy to announce that support for the Dart language is now available in beta!Dart gRPC support works with the Dart SDK, version 1.24.3 or higher, and currently supports the Flutter and VM/Server platforms.

Creating a server and writing gRPC service definitions

gRPC services typically describe their endpoints and data serialization using Protocol Buffers v3. Here is a small example service definition which defines a service ‘Greeter’ with a single rpc message ‘SayHello’ (the number ‘1’ in the two messages specifies the unique ID of the message field):

Once you have defined the service, you can automatically generate the skeleton of the server:

protoc --dart_out=grpc:generated -Iprotos protos/greeter.proto

This will produce a GreeterServiceBase class in the generated diretory, which you then subclass to add the actual service implementation:

Calling the server with a gRPC client

When we generated the service stub above, the protoc compiler also generated a client library:

With that, calling into the service from the client tier is simple:

When run, this will print the following output:

Greeter client received: Hello, Michael!

Next steps

To get started with gRPC in Dart, please take a look at our new Dart gRPC QuickStart, which walks you through running and extending the Greeter example. Next, check out the Dart gRPC tutorial.

Should you encounter any problems, please file an issue. We would also gladly hear your feedback on any changes or additions you like to see; for example, we have heard several requests for supporting the gRPC-Web protocol. One concrete way of offering quick feedback is to ‘cast a vote’ on an issue by pressing the GitHub thumbs-up 👍 button on the top-most comment of an issue.

We look forward to seeing what you might build with gRPC for Dart!

Like what you read? Give Michael Thomsen a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.