This project demonstrates a gRPC implementation using a Rust server and a React client.
The project consists of two main components:
- A gRPC server implemented in Rust
- A React client that communicates with the server using gRPC-Web
- Rust (latest stable version)
- Node.js (v14 or later)
- npm or yarn
- Protocol Buffers compiler (protoc)
- gRPC-Web plugin for protoc
-
Navigate to the server directory:
cd server
-
Build the server:
cargo build --release
-
Run the server:
cargo run --release
The server will start on localhost:50051
by default.
-
Navigate to the client directory:
cd client
-
Install dependencies:
npm install
or
yarn install
-
Start the development server:
npm start
or
yarn start
The client will be available at http://localhost:3000
.
The gRPC service is defined in proto/service.proto
. To generate the necessary code:
-
For the Rust server:
protoc -I proto service.proto --rust_out=server/src --grpc_out=server/src --plugin=protoc-gen-grpc=`which grpc_rust_plugin`
-
For the React client:
protoc -I proto service.proto --js_out=import_style=commonjs:client/src --grpc-web_out=import_style=typescript,mode=grpcwebtext:client/src