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

..03-May-2022-

.circleci/H07-Oct-2021-6356

cmd/grpcurl/H07-Oct-2021-929803

internal/testing/H07-Oct-2021-7,4366,206

releasing/H07-Oct-2021-164103

src/github.com/fullstorydev/grpcurl/H03-May-2022-

vendor/H03-May-2022-5,552,8004,606,149

.gitignoreH A D07-Oct-202121 43

.goreleaser.ymlH A D07-Oct-2021609 3634

DockerfileH A D07-Oct-2021883 2823

LICENSEH A D07-Oct-20211.1 KiB2117

MakefileH A D07-Oct-20211.9 KiB7953

README.mdH A D07-Oct-202110.7 KiB243191

desc_source.goH A D07-Oct-202110.1 KiB305244

desc_source_test.goH A D07-Oct-20211.9 KiB6352

format.goH A D07-Oct-202116.6 KiB530342

format_test.goH A D07-Oct-20217.4 KiB310280

go.modH A D07-Oct-2021424 1512

go.sumH A D07-Oct-202132.2 KiB328327

grpcurl.goH A D07-Oct-202122.6 KiB699515

grpcurl_test.goH A D07-Oct-202129.1 KiB882734

invoke.goH A D07-Oct-202112.7 KiB406278

mk-test-files.shH A D07-Oct-20211.4 KiB5832

tls_settings_test.goH A D07-Oct-202111.5 KiB362296

README.md

1# gRPCurl
2[![Build Status](https://circleci.com/gh/fullstorydev/grpcurl/tree/master.svg?style=svg)](https://circleci.com/gh/fullstorydev/grpcurl/tree/master)
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 secure/TLS servers _and_ plain-text servers (i.e. no TLS) and has
39numerous options for TLS configuration. It also supports mutual TLS, where the client is
40required to present a client 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
52### Homebrew (macOS)
53
54On macOS, `grpcurl` is available via Homebrew:
55```shell
56brew install grpcurl
57```
58
59### Docker
60
61For platforms that support Docker, you can download an image that lets you run `grpcurl`:
62```shell
63# Download image
64docker pull fullstorydev/grpcurl:latest
65# Run the tool
66docker run fullstorydev/grpcurl api.grpc.me:443 list
67```
68Note that there are some pitfalls when using docker:
69- If you need to interact with a server listening on the host's loopback network, you must specify the host as `host.docker.internal` instead of `localhost` (for Mac or Windows) _OR_ have the container use the host network with `-network="host"` (Linux only).
70- If you need to provide proto source files or descriptor sets, you must mount the folder containing the files as a volume (`-v $(pwd):/protos`) and adjust the import paths to container paths accordingly.
71- If you want to provide the request message via stdin, using the `-d @` option, you need to use the `-i` flag on the docker command.
72
73### Other Packages
74
75There are numerous other ways to install `grpcurl`, thanks to support from third parties that
76have created recipes/packages for it. These include other ways to install `grpcurl` on a variety
77of environments, including Windows and myriad Linux distributions.
78
79You can see more details and the full list of other packages for `grpcurl` at _repology.org_:
80https://repology.org/project/grpcurl/information
81
82### From Source
83If you already have the [Go SDK](https://golang.org/doc/install) installed, you can use the `go`
84tool to install `grpcurl`:
85```shell
86go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest
87```
88
89This installs the command into the `bin` sub-folder of wherever your `$GOPATH`
90environment variable points. (If you have no `GOPATH` environment variable set,
91the default install location is `$HOME/go/bin`). If this directory is already in
92your `$PATH`, then you should be good to go.
93
94If you have already pulled down this repo to a location that is not in your
95`$GOPATH` and want to build from the sources, you can `cd` into the repo and then
96run `make install`.
97
98If you encounter compile errors and are using a version of the Go SDK older than 1.13,
99you could have out-dated versions of `grpcurl`'s dependencies. You can update the
100dependencies by running `make updatedeps`. Or, if you are using Go 1.11 or 1.12, you
101can add `GO111MODULE=on` as a prefix to the commands above, which will also build using
102the right versions of dependencies (vs. whatever you may already have in your `GOPATH`).
103
104## Usage
105The usage doc for the tool explains the numerous options:
106```shell
107grpcurl -help
108```
109
110In the sections below, you will find numerous examples demonstrating how to use
111`grpcurl`.
112
113### Invoking RPCs
114Invoking an RPC on a trusted server (e.g. TLS without self-signed key or custom CA)
115that requires no client certs and supports server reflection is the simplest thing to
116do with `grpcurl`. This minimal invocation sends an empty request body:
117```shell
118grpcurl grpc.server.com:443 my.custom.server.Service/Method
119
120# no TLS
121grpcurl -plaintext grpc.server.com:80 my.custom.server.Service/Method
122```
123
124To send a non-empty request, use the `-d` argument. Note that all arguments must come
125*before* the server address and method name:
126```shell
127grpcurl -d '{"id": 1234, "tags": ["foo","bar"]}' \
128    grpc.server.com:443 my.custom.server.Service/Method
129```
130
131As can be seen in the example, the supplied body must be in JSON format. The body will
132be parsed and then transmitted to the server in the protobuf binary format.
133
134If you want to include `grpcurl` in a command pipeline, such as when using `jq` to
135create a request body, you can use `-d @`, which tells `grpcurl` to read the actual
136request body from stdin:
137```shell
138grpcurl -d @ grpc.server.com:443 my.custom.server.Service/Method <<EOM
139{
140  "id": 1234,
141  "tags": [
142    "foor",
143    "bar"
144  ]
145}
146EOM
147```
148
149### Listing Services
150To list all services exposed by a server, use the "list" verb. When using `.proto` source
151or protoset files instead of server reflection, this lists all services defined in the
152source or protoset files.
153```shell
154# Server supports reflection
155grpcurl localhost:8787 list
156
157# Using compiled protoset files
158grpcurl -protoset my-protos.bin list
159
160# Using proto sources
161grpcurl -import-path ../protos -proto my-stuff.proto list
162```
163
164The "list" verb also lets you see all methods in a particular service:
165```shell
166grpcurl localhost:8787 list my.custom.server.Service
167```
168
169### Describing Elements
170The "describe" verb will print the type of any symbol that the server knows about
171or that is found in a given protoset file. It also prints a description of that
172symbol, in the form of snippets of proto source. It won't necessarily be the
173original source that defined the element, but it will be equivalent.
174
175```shell
176# Server supports reflection
177grpcurl localhost:8787 describe my.custom.server.Service.MethodOne
178
179# Using compiled protoset files
180grpcurl -protoset my-protos.bin describe my.custom.server.Service.MethodOne
181
182# Using proto sources
183grpcurl -import-path ../protos -proto my-stuff.proto describe my.custom.server.Service.MethodOne
184```
185
186## Descriptor Sources
187The `grpcurl` tool can operate on a variety of sources for descriptors. The descriptors
188are required, in order for `grpcurl` to understand the RPC schema, translate inputs
189into the protobuf binary format as well as translate responses from the binary format
190into text. The sections below document the supported sources and what command-line flags
191are needed to use them.
192
193### Server Reflection
194
195Without 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).
196
197Examples for how to set up server reflection can be found [here](https://github.com/grpc/grpc/blob/master/doc/server-reflection.md#known-implementations).
198
199When using reflection, the server address (host:port or path to Unix socket) is required
200even for "list" and "describe" operations, so that `grpcurl` can connect to the server
201and ask it for its descriptors.
202
203### Proto Source Files
204To use `grpcurl` on servers that do not support reflection, you can use `.proto` source
205files.
206
207In addition to using `-proto` flags to point `grpcurl` at the relevant proto source file(s),
208you may also need to supply `-import-path` flags to tell `grpcurl` the folders from which
209dependencies can be imported.
210
211Just like when compiling with `protoc`, you do *not* need to provide an import path for the
212location of the standard protos included with `protoc` (which contain various "well-known
213types" with a package definition of `google.protobuf`). These files are "known" by `grpcurl`
214as a snapshot of their descriptors is built into the `grpcurl` binary.
215
216When using proto sources, you can omit the server address (host:port or path to Unix socket)
217when using the "list" and "describe" operations since they only need to consult the proto
218source files.
219
220### Protoset Files
221You can also use compiled protoset files with `grpcurl`. If you are scripting `grpcurl` and
222need to re-use the same proto sources for many invocations, you will see better performance
223by using protoset files (since it skips the parsing and compilation steps with each
224invocation).
225
226Protoset files contain binary encoded `google.protobuf.FileDescriptorSet` protos. To create
227a protoset file, invoke `protoc` with the `*.proto` files that define the service:
228```shell
229protoc --proto_path=. \
230    --descriptor_set_out=myservice.protoset \
231    --include_imports \
232    my/custom/server/service.proto
233```
234
235The `--descriptor_set_out` argument is what tells `protoc` to produce a protoset,
236and the `--include_imports` argument is necessary for the protoset to contain
237everything that `grpcurl` needs to process and understand the schema.
238
239When using protosets, you can omit the server address (host:port or path to Unix socket)
240when using the "list" and "describe" operations since they only need to consult the
241protoset files.
242
243