• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

cmd/grpcurl/H31-Jul-2020-

releasing/H31-Jul-2020-

testing/H03-May-2022-

.gitignoreH A D31-Jul-202014

.goreleaser.ymlH A D31-Jul-2020397

.travis.ymlH A D31-Jul-2020439

DockerfileH A D31-Jul-2020915

LICENSEH A D31-Jul-20201.1 KiB

MakefileH A D31-Jul-20201.9 KiB

README.mdH A D31-Jul-20209.2 KiB

desc_source.goH A D31-Jul-202010 KiB

desc_source_test.goH A D31-Jul-20201.8 KiB

format.goH A D31-Jul-202015.9 KiB

format_test.goH A D31-Jul-20206.9 KiB

go.modH A D31-Jul-2020529

go.sumH A D31-Jul-202056.6 KiB

grpcurl.goH A D31-Jul-202021.5 KiB

grpcurl_test.goH A D31-Jul-202029.2 KiB

invoke.goH A D31-Jul-202012.1 KiB

mk-test-files.shH A D31-Jul-20201.4 KiB

tls_settings_test.goH A D31-Jul-202011.2 KiB

README.md

1# gRPCurl
2[![Build Status](https://travis-ci.com/fullstorydev/grpcurl.svg?branch=master)](https://travis-ci.com/github/fullstorydev/grpcurl/branches)
3[![Go Report Card](https://goreportcard.com/badge/github.com/fullstorydev/grpcurl)](https://goreportcard.com/report/github.com/fullstorydev/grpcurl)
4
5`grpcurl` is a command-line tool that lets you interact with gRPC servers. It's
6basically `curl` for gRPC servers.
7
8The main purpose for this tool is to invoke RPC methods on a gRPC server from the
9command-line. gRPC servers use a binary encoding on the wire
10([protocol buffers](https://developers.google.com/protocol-buffers/), or "protobufs"
11for short). So they are basically impossible to interact with using regular `curl`
12(and older versions of `curl` that do not support HTTP/2 are of course non-starters).
13This program accepts messages using JSON encoding, which is much more friendly for both
14humans and scripts.
15
16With this tool you can also browse the schema for gRPC services, either by querying
17a server that supports [server reflection](https://github.com/grpc/grpc/blob/master/src/proto/grpc/reflection/v1alpha/reflection.proto),
18by reading proto source files, or by loading in compiled "protoset" files (files that contain
19encoded file [descriptor protos](https://github.com/google/protobuf/blob/master/src/google/protobuf/descriptor.proto)).
20In fact, the way the tool transforms JSON request data into a binary encoded protobuf
21is using that very same schema. So, if the server you interact with does not support
22reflection, you will either need the proto source files that define the service or need
23protoset files that `grpcurl` can use.
24
25This repo also provides a library package, `github.com/fullstorydev/grpcurl`, that has
26functions for simplifying the construction of other command-line tools that dynamically
27invoke gRPC endpoints. This code is a great example of how to use the various packages of
28the [protoreflect](https://godoc.org/github.com/jhump/protoreflect) library, and shows
29off what they can do.
30
31See also the [`grpcurl` talk at GopherCon 2018](https://www.youtube.com/watch?v=dDr-8kbMnaw).
32
33## Features
34`grpcurl` supports all kinds of RPC methods, including streaming methods. You can even
35operate bi-directional streaming methods interactively by running `grpcurl` from an
36interactive terminal and using stdin as the request body!
37
38`grpcurl` supports both plain-text and TLS servers and has numerous options for TLS
39configuration. It also supports mutual TLS, where the client is required to present a
40client certificate.
41
42As mentioned above, `grpcurl` works seamlessly if the server supports the reflection
43service. If not, you can supply the `.proto` source files or you can supply protoset
44files (containing compiled descriptors, produced by `protoc`) to `grpcurl`.
45
46## Installation
47
48### Binaries
49
50Download the binary from the [releases](https://github.com/fullstorydev/grpcurl/releases) page.
51
52On macOS, `grpcurl` is available via Homebrew:
53```shell
54brew install grpcurl
55```
56
57### From Source
58You can use the `go` tool to install `grpcurl`:
59```shell
60go get github.com/fullstorydev/grpcurl/...
61go install github.com/fullstorydev/grpcurl/cmd/grpcurl
62```
63
64This installs the command into the `bin` sub-folder of wherever your `$GOPATH`
65environment variable points. If this directory is already in your `$PATH`, then
66you should be good to go.
67
68If you have already pulled down this repo to a location that is not in your
69`$GOPATH` and want to build from the sources, you can `cd` into the repo and then
70run `make install`.
71
72If you encounter compile errors, you could have out-dated versions of `grpcurl`'s
73dependencies. You can update the dependencies by running `make updatedeps`. You can
74also use [`vgo`](https://github.com/golang/vgo) to install, which will use the right
75versions of dependencies. Or, if you are using Go 1.11, you can add `GO111MODULE=on`
76as a prefix to the commands above, which will also build using the right versions of
77dependencies (vs. whatever you may already in your `GOPATH`).
78
79## Usage
80The usage doc for the tool explains the numerous options:
81```shell
82grpcurl -help
83```
84
85In the sections below, you will find numerous examples demonstrating how to use
86`grpcurl`.
87
88### Invoking RPCs
89Invoking an RPC on a trusted server (e.g. TLS without self-signed key or custom CA)
90that requires no client certs and supports server reflection is the simplest thing to
91do with `grpcurl`. This minimal invocation sends an empty request body:
92```shell
93grpcurl grpc.server.com:443 my.custom.server.Service/Method
94```
95
96To send a non-empty request, use the `-d` argument. Note that all arguments must come
97*before* the server address and method name:
98```shell
99grpcurl -d '{"id": 1234, "tags": ["foo","bar"]}' \
100    grpc.server.com:443 my.custom.server.Service/Method
101```
102
103As can be seen in the example, the supplied body must be in JSON format. The body will
104be parsed and then transmitted to the server in the protobuf binary format.
105
106If you want to include `grpcurl` in a command pipeline, such as when using `jq` to
107create a request body, you can use `-d @`, which tells `grpcurl` to read the actual
108request body from stdin:
109```shell
110grpcurl -d @ grpc.server.com:443 my.custom.server.Service/Method <<EOM
111{
112  "id": 1234,
113  "tags": [
114    "foor",
115    "bar"
116  ]
117}
118EOM
119```
120
121### Listing Services
122To list all services exposed by a server, use the "list" verb. When using `.proto` source
123or protoset files instead of server reflection, this lists all services defined in the
124source or protoset files.
125```shell
126# Server supports reflection
127grpcurl localhost:8787 list
128
129# Using compiled protoset files
130grpcurl -protoset my-protos.bin list
131
132# Using proto sources
133grpcurl -import-path ../protos -proto my-stuff.proto list
134```
135
136The "list" verb also lets you see all methods in a particular service:
137```shell
138grpcurl localhost:8787 list my.custom.server.Service
139```
140
141### Describing Elements
142The "describe" verb will print the type of any symbol that the server knows about
143or that is found in a given protoset file. It also prints a description of that
144symbol, in the form of snippets of proto source. It won't necessarily be the
145original source that defined the element, but it will be equivalent.
146
147```shell
148# Server supports reflection
149grpcurl localhost:8787 describe my.custom.server.Service.MethodOne
150
151# Using compiled protoset files
152grpcurl -protoset my-protos.bin describe my.custom.server.Service.MethodOne
153
154# Using proto sources
155grpcurl -import-path ../protos -proto my-stuff.proto describe my.custom.server.Service.MethodOne
156```
157
158## Descriptor Sources
159The `grpcurl` tool can operate on a variety of sources for descriptors. The descriptors
160are required, in order for `grpcurl` to understand the RPC schema, translate inputs
161into the protobuf binary format as well as translate responses from the binary format
162into text. The sections below document the supported sources and what command-line flags
163are needed to use them.
164
165### Server Reflection
166
167Without any additional command-line flags, `grpcurl` will try to use [server reflection](https://github.com/grpc/grpc/blob/master/src/proto/grpc/reflection/v1alpha/reflection.proto).
168
169Examples for how to set up server reflection can be found [here](https://github.com/grpc/grpc/blob/master/doc/server-reflection.md#known-implementations).
170
171When using reflection, the server address (host:port or path to Unix socket) is required
172even for "list" and "describe" operations, so that `grpcurl` can connect to the server
173and ask it for its descriptors.
174
175### Proto Source Files
176To use `grpcurl` on servers that do not support reflection, you can use `.proto` source
177files.
178
179In addition to using `-proto` flags to point `grpcurl` at the relevant proto source file(s),
180you may also need to supply `-import-path` flags to tell `grpcurl` the folders from which
181dependencies can be imported.
182
183Just like when compiling with `protoc`, you do *not* need to provide an import path for the
184location of the standard protos included with `protoc` (which contain various "well-known
185types" with a package definition of `google.protobuf`). These files are "known" by `grpcurl`
186as a snapshot of their descriptors is built into the `grpcurl` binary.
187
188When using proto sources, you can omit the server address (host:port or path to Unix socket)
189when using the "list" and "describe" operations since they only need to consult the proto
190source files.
191
192### Protoset Files
193You can also use compiled protoset files with `grpcurl`. If you are scripting `grpcurl` and
194need to re-use the same proto sources for many invocations, you will see better performance
195by using protoset files (since it skips the parsing and compilation steps with each
196invocation).
197
198Protoset files contain binary encoded `google.protobuf.FileDescriptorSet` protos. To create
199a protoset file, invoke `protoc` with the `*.proto` files that define the service:
200```shell
201protoc --proto_path=. \
202    --descriptor_set_out=myservice.protoset \
203    --include_imports \
204    my/custom/server/service.proto
205```
206
207The `--descriptor_set_out` argument is what tells `protoc` to produce a protoset,
208and the `--include_imports` argument is necessary for the protoset to contain
209everything that `grpcurl` needs to process and understand the schema.
210
211When using protosets, you can omit the server address (host:port or path to Unix socket)
212when using the "list" and "describe" operations since they only need to consult the
213protoset files.
214
215