This shows how you can use .proto files as the source of truth for APIs across the stack. This includes:
- Building a gRPC server, connecting it to a gRPC client (in Go)
- Building an HTTP server, and an HTTP client (in Typescript)
The advantage of this workflow is that you only write your API schemas in one place (proto files) and then those API definitions can be shared across your entire stack: Between the client and server, and between services. This is made possible by gRPC and the Connect Protocol which enables type-safe, browser-compatible gRPC APIs.
Start the Go servers. This will start the gRPC servers and will also start up the :
This also builds and starts HTTPs from the service implementation. By default, Connect handlers support Connect, gRPC, and gRPC-Web protocols.
task setup
task gen
task devCall the HTTP server. You can see the request goes through fine to the greet service:
task call:http-helloThis also works, now we are hitting the endpoint via gRPC:
task call:grpc-helloFinally, you can also call the math service, which is just a different service:
task call:grpc-addMake sure the Go servers are running first:
task setup
task gen
task devNext, run the HTTP client:
task start:runThis will compile the Typescript code, using the Connect protocol, and send requests to the Go server.