Exporting GRPC as a JSON API
In the Understanding GRPC clients recipe from Chapter 6, Web Clients and APIs, we wrote a basic GRPC server and client. This recipe will expand on that idea by putting common RPC functions in a package and wrapping them in both a GRPC server and a standard web handler. This can be useful when your API wants to support both types of client, but you don't want to replicate code for common functionality.
Getting ready
Configure your environment according to these steps:
- Refer to the steps given in the Getting ready section of the Working with web handlers, requests, and ResponseWriters recipe.
- Install GRPC from https://github.com/grpc/grpc/blob/master/INSTALL.md.
- Run the
go get github.com/golang/protobuf/proto
command. - Run the
go get github.com/golang/protobuf/protoc-gen-go
command.
How to do it...
These steps cover writing and running your application:
- From your terminal/console application, create and navigate to the
chapter7/grpcjson
directory.
- Copy tests from https:/...