Feature request/idea: generate types for HTTP endpoints generated via the transcoder
We use ts-proto to generate types for our frontend that uses http to communicate with the backend.
https://github.com/grpc-ecosystem/grpc-gateway allows us to auto generate endpoints based on simple .proto descriptors
ie:
syntax = "proto3";
package your.service.v1;
option go_package = "github.com/yourorg/yourprotos/gen/go/your/service/v1";
import "google/api/annotations.proto";
message StringMessage {
string value = 1;
}
service YourService {
rpc Echo(StringMessage) returns (StringMessage) {
option (google.api.http) = {
post: "/v1/example/echo"
body: "*"
};
}
}
It also supports url parameters, query parametes and body types.
From this information I think it should be possible to generate something that connects RequestMessage with url (with url assembly) and the ResponseMessage. So we do not loose type safety here.
What do you think? I would be happy to look into and help with the implementation
Hi @geritol ; I'm not really an expert on grpc-gateway, but it sounds like it's similar to grpc-web (which ts-proto does support), but with more flexibility in how the service is exposed to the outside world?
If so, yeah, we have an implementation for grpc-web:
https://github.com/stephenh/ts-proto/blob/main/src/generate-grpc-web.ts
If you'd like to work on a --ts_proto_opt=outputClientImpl=grpc-gateway option that is similar but for grpc-gateway, that sounds good to me.
I probably won't be able to help much, but can at least review/accept PRs as you work through the approach. Thanks!
but with more flexibility in how the service is exposed to the outside world?
@stephenh the gRPC-Gateway is a plugin of the Google protocol buffers compiler protoc. It reads protobuf service definitions and generates a reverse-proxy server which translates a RESTful HTTP API into gRPC.
Thank you! Will hopefully have time to come up and implement a solution!
Hi @stephenh , what's the status of https://github.com/stephenh/ts-proto/blob/main/src/generate-grpc-web.ts? just saw it get some updates recently, will it happen sooner or what is lacking of to make it support grpc-gateway? Thanks
Hi @jaysonwu991 , I personally don't use either grpc-web or grpc-gateway, so honestly am not sure of the gap between support/features for both. I know ts-proto uses are using grpc-web in production, but that's about it.
We would need a contributor who really wants to own/contribute the grpc-gateway implementation to figure how what is necessary and submit a PR. If you're interesting in this, happy to help give suggestions here and there on the core ts-proto codebase, just with against the disclaimer IANAE on the grpc-web/grpc-gateway projects themselves. Thanks!