https://github.com/gbaptista/grpc-demos
Examples of gRPC server and clients (Go, Ruby and Javascript).
https://github.com/gbaptista/grpc-demos
envoy go golang grpc javascript react ruby
Last synced: 6 months ago
JSON representation
Examples of gRPC server and clients (Go, Ruby and Javascript).
- Host: GitHub
- URL: https://github.com/gbaptista/grpc-demos
- Owner: gbaptista
- Created: 2018-12-02T23:00:42.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-03T17:50:13.000Z (almost 7 years ago)
- Last Synced: 2025-02-14T13:50:32.502Z (8 months ago)
- Topics: envoy, go, golang, grpc, javascript, react, ruby
- Language: JavaScript
- Homepage:
- Size: 70.3 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# gRPC Demos
- [Proto](#proto)
- [Go Server](#go-server)
- [Go Client](#go-client)
- [Ruby Client](#ruby-client)
- [Javascript Web Client](#javascript-web-client)## Proto
```proto
syntax = "proto3";package hello;
service HelloService {
rpc SayHello (HelloRequest) returns (HelloReply);
}message HelloRequest {
string name = 1;
}message HelloReply {
string message = 1;
}
```## Go Server
```shell
. run.sh compile_protos
. run.sh go_server
``````go
func (server *grpc_server) SayHello(
ctx context.Context, args *pb.HelloRequest) (*pb.HelloReply, error) {return &pb.HelloReply{
Message: "hello " + args.Name + "!"}, nil
}server := buildServer()
listenServer(server, "50051")
```## Go Client
```shell
. run.sh go_client
``````go
_, client := buildClient("localhost:50051")response, _ := client.SayHello(
context.Background(), &pb.HelloRequest{Name: "gbaptista"})response.Message // 'hello gbaptista!'
```## Ruby Client
```shell
. run.sh ruby_client
``````ruby
client = Hello::Client.new(
'localhost:50051',
:this_channel_is_insecure
)response = client.say_hello(
Hello::HelloRequest.new(name: 'gbaptista')
)response.message # => 'hello gbaptista!'
```## Javascript Web Client
```shell
docker-compose up -dcd src/web_js_client/
npm install
npm start> http://localhost:8080
``````es6
grpc_client = new HelloServiceClient(
'http://localhost:50052'
);const request = new HelloRequest();
request.setName('gbaptista');grpc_client.sayHello(request, {}, (error, response) => {
if(error) {
console.error(error);
} else {
console.error(response); // 'hello gbaptista!'
}
});
```