fullstorydev / grpcurl

Like cURL, but for gRPC: Command-line tool for interacting with gRPC servers
MIT License
10.35k stars 497 forks source link

Whether I can get the structure of the request parameters and response parameters of the grpc interface, this is very useful to me #425

Open l54808821 opened 8 months ago

l54808821 commented 8 months ago

Whether I can get the structure of the request parameters and response parameters of the grpc interface, this is very useful to me

l54808821 commented 8 months ago
image

What I get now is only a simple description, which does not satisfy me

jhump commented 8 months ago

@l54808821, the --protoset-out flag will save the schema to a file that is a binary encoded google.protobuf.FileDescriptorSet. That is the typical format of a Protobuf "schema".

This file includes the definitions from the proto source file that defines the elements you are listing or describing as well as all of the files it imports. Other Protobuf runtime APIs that support reflection often have a way to work with these descriptors. In Go, for example, it's various packages under google.golang.org/protobuf/reflection, with protodesc.NewFiles being a useful entry point. The general technique is to read in the file contents, unmarshal those bytes into a google.protobuf.FileDescriptorSet message, and then use these other APIs to turn that message into a more useful type.

l54808821 commented 8 months ago

@jhump Hello, "fullstorydev/grpcui" project this interface (" http://127.0.0.1:63806/metadata? method=team.Team.add ") return information is what I want, I wonder if it can be obtained by command in this project

image image
jhump commented 7 months ago

I wonder if it can be obtained by command in this project

No, not quite. Most of the logic in this package uses the Go protobuf runtime's reflection facilities: https://pkg.go.dev/google.golang.org/protobuf/reflect

As such, nearly everything works with descriptors (per my earlier reply). Only the browser JS code (which doesn't use a protobuf runtime so doesn't have any way to work with descriptors) uses this representation, for building the HTML form. As such this format is not available outside of the endpoint you highlighted.

What exactly are you trying to do that would make this representation useful?

l54808821 commented 7 months ago

@jhump I made a web tool that needed to get a preset request body based on the grpc interface, so