Skip to content

Latest commit

 

History

History
38 lines (27 loc) · 1.28 KB

README.md

File metadata and controls

38 lines (27 loc) · 1.28 KB

Usage Example

This is an example that demonstrates grpc-gateway-client in action. The example contains a simple gRPC service that is fronted by a grpc-gateway. The service is defined in helloworld.proto and has a single gRPC method that it translated to /v1/example/echo REST endpoint by grpc-gateway.

Server

Server implementation is located in server/main.go. It starts a gRPC server and a grpc-gateway server. The grpc-gateway server is listening on port 8081:

Start server using the following command:

$ go run server/main.go
Listening on :8081

Test it using curl:

$ curl "http://localhost:8081/v1/example/echo?name=world"
{"message":"Hello world"}

Client

The client is generated by grpc-gateway-client that provides a clean typed interface to interact with the gRPC service over REST API:

client := grpc_gateway_client_example.NewGreeterGatewayClient(gateway.NewClient(baseURL))
resp, err := client.SayHello(context.Background(), &grpc_gateway_client_example.HelloRequest{Name: "World"})
if err != nil {
    panic(err)
}
    fmt.Println(resp.Message)