Skip to content

A basic example of using React JS with a gRPC client. Used envoy as a proxy

Notifications You must be signed in to change notification settings

marcosmartinez7/grpc-react-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gRPC-react-example

This project was bootstrapped with Create React App.

PoC

Having a Greeter service implemented on a node js and a Envoy proxy server, create a react application that implements the Greeter service client.

Alt text

To implement the service client we use https://github.com/grpc/grpc-web

Grpc web overview: https://github.com/grpc/grpc-web/

HelloWorld example: https://github.com/grpc/grpc-web/tree/master/net/grpc/gateway/examples/helloworld (the helloworld example worked with serve but not with python http servers)

Note: the example has the full code but the ./helloworld_pb.js and ./helloworld_grpc_web_pb.js that must be generated (See step by step guide)

This project is a merge of CRA and the HelloWorld example

Step by step guide

Prerequisites:

You need to have installed:

  1. Git clone the project
  2. Npm/yarn install
  3. Generate the Request, Reply and Client code:
protoc -I=. helloworld.proto \
  --js_out=import_style=commonjs:. \
  --grpc-web_out=import_style=commonjs,mode=grpcwebtext:.
  1. After the command runs successfully, you should now see two new files generated in the current directory:

helloworld_pb.js: this contains the HelloRequest and HelloReply classes helloworld_grpc_web_pb.js: this contains the GreeterClient class These are also the 2 files that our client.js file imported earlier in the example.

  1. Run node.js server backend (runs at 9090): node server.js
  2. Run the Envoy proxy. The envoy.yaml file configures Envoy to listen to browser requests at port :8080, and forward them to port :9090 (see above).
$ docker build -t helloworld/envoy -f ./envoy.Dockerfile .
$ docker run -d -p 8080:8080 --network=host helloworld/envoy
  1. Run the react client: yarn start
  2. Access to localhost:8081, check out the console, it should print the gRPC server response.

Alt text

Interesting links

About

A basic example of using React JS with a gRPC client. Used envoy as a proxy

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published