grpc-dart/example/grpc-web
Slava Egorov 9a0b4642ef
Allow 4.0.0 version for protobuf dependency and prepare to release 4.0.3 (#774)
Fixes https://github.com/grpc/grpc-dart/issues/768
2025-03-31 15:42:24 +02:00
..
lib Fix web and prepare to publish 4.0.2 2025-03-31 10:22:25 +02:00
protos grpc-web support (#191) 2019-06-17 13:31:07 +02:00
web fix: Updates the grpc-web example to avoid dart:html (#748) 2025-02-21 14:11:03 +01:00
README.md Migrate examples to Dart null safety (#536) 2022-01-04 10:05:22 +10:00
analysis_options.yaml Migrate examples to Dart null safety (#536) 2022-01-04 10:05:22 +10:00
pubspec.yaml Allow 4.0.0 version for protobuf dependency and prepare to release 4.0.3 (#774) 2025-03-31 15:42:24 +02:00

README.md

Description

The grpc-web example shows how to use the Dart gRPC library with a gRPC-Web capable server.

This is meant to be used with the echo example provided by the grpc-web repository. The definition of the service is given in echo.proto.

Prerequisites

Install 'webdev', by running

$ dart pub global activate webdev

You will need a clone of the grpc-web repository to run the example server.

Run the sample code

Follow the instructions for starting the grpc-web example server. The simplest version of this involves running the grpc-web server in a docker container with:

$ docker-compose up node-server envoy commonjs-client

To compile and run the example, assuming you are in the root of the grpc-web folder, i.e., .../example/grpc-web/, first get the dependencies by running:

$ dart pub get

Compile and run the website with:

$ webdev serve web:9000

Note that the alternate port (9000) is necessary because the grpc-web server runs the grpc server on port 8080 by default (the same as webdev).

You can then navigate to http://localhost:9000/ to try out the example.

Regenerate the stubs

If you have made changes to the message or service definition in protos/echo.proto and need to regenerate the corresponding Dart files, you will need to have protoc version 3.0.0 or higher and the Dart protoc plugin version 16.0.0 or higher on your PATH.

To install protoc, see the instructions on the Protocol Buffers website.

The easiest way to get the Dart protoc plugin is by running

$ dart pub global activate protoc_plugin

and follow the directions to add ~/.pub-cache/bin to your PATH, if you haven't already done so.

You can now regenerate the Dart files by running

$ protoc --dart_out=grpc:lib/src/generated -Iprotos protos/echo.proto