blob: 77c3d078ad99bc80c61300e051d215efcda91fc1 [file] [log] [blame] [view]
Yang Gaoac4b3a62016-06-08 15:00:25 -07001# gRPC command line tool
2
3## Overview
4
Eric Gribkoff132fd422017-01-26 09:23:33 -08005This document describes the command line tool that comes with gRPC repository. It is desirable to have command line
6tools written in other languages roughly follow the same syntax and flags.
Yang Gaoac4b3a62016-06-08 15:00:25 -07007
8At this point, the tool needs to be built from source, and it should be moved out to grpc-tools repository as a stand
9alone application once it is mature enough.
10
Yang Gao0aa822b2016-06-09 17:23:38 -070011## Core functionality
Yang Gaoac4b3a62016-06-08 15:00:25 -070012
13The command line tool can do the following things:
14
15- Send unary rpc.
16- Attach metadata and display received metadata.
17- Handle common authentication to server.
Yuchen Zeng9cb94452016-07-20 16:39:31 -070018- Infer request/response types from server reflection result.
Yang Gaoac4b3a62016-06-08 15:00:25 -070019- Find the request/response types from a given proto file.
20- Read proto request in text form.
21- Read request in wire form (for protobuf messages, this means serialized binary form).
22- Display proto response in text form.
23- Write response in wire form to a file.
24
25The command line tool should support the following things:
26
27- List server services and methods through server reflection.
Yang Gaoac4b3a62016-06-08 15:00:25 -070028- Fine-grained auth control (such as, use this oauth token to talk to the server).
29- Send streaming rpc.
30
31## Code location
32
Eric Gribkoff132fd422017-01-26 09:23:33 -080033To use the tool, you need to get the grpc repository and make sure your system
34has the prerequisites for building grpc from source, given in the [installation
35instructions](https://github.com/grpc/grpc/blob/master/INSTALL.md).
36
37In order to build the grpc command line tool from a fresh clone of the grpc
38repository, you need to run the following command to update submodules:
39
40```
41git submodule update --init
42```
43
44You also need to have the gflags library installed on your system. On Linux
45systems, gflags can be installed with the following command:
46
47```
48sudo apt-get install libgflags-dev
49```
50
51Once the prerequisites are satisfied, you can build the command line tool with
52the command:
Yang Gaoac4b3a62016-06-08 15:00:25 -070053
54```
Yang Gao0aa822b2016-06-09 17:23:38 -070055$ make grpc_cli
Yang Gaoac4b3a62016-06-08 15:00:25 -070056```
57
58The main file can be found at
59https://github.com/grpc/grpc/blob/master/test/cpp/util/grpc_cli.cc
60
61## Usage
62
63### Basic usage
64
65Send a rpc to a helloworld server at `localhost:50051`:
66
67```
Yuchen Zeng9cb94452016-07-20 16:39:31 -070068$ bins/opt/grpc_cli call localhost:50051 SayHello "name: 'world'" \
69 --enable_ssl=false
Yang Gaoac4b3a62016-06-08 15:00:25 -070070```
71
72On success, the tool will print out
73
74```
75Rpc succeeded with OK status
Yuchen Zeng9cb94452016-07-20 16:39:31 -070076Response:
Yang Gaoac4b3a62016-06-08 15:00:25 -070077 message: "Hello world"
78```
79
80The `localhost:50051` part indicates the server you are connecting to. `SayHello` is (part of) the
Yuchen Zeng9cb94452016-07-20 16:39:31 -070081gRPC method string. Then `"name: 'world'"` is the text format of the request proto message. We are
82not using ssl here by `--enable_ssl=false`. For information on more flags, look at the comments of `grpc_cli.cc`.
83
84### Use local proto files
85
86If the server does not have the server reflection service, you will need to provide local proto
87files containing the service definition. The tool will try to find request/response types from
88them.
89
90```
91$ bins/opt/grpc_cli call localhost:50051 SayHello "name: 'world'" \
92 --protofiles=examples/protos/helloworld.proto --enable_ssl=false
93```
94
95If the proto files is not under current directory, you can use `--proto_path` to specify a new
96search root.
Yang Gaoac4b3a62016-06-08 15:00:25 -070097
98### Send non-proto rpc
99
100For using gRPC with protocols other than probobuf, you will need the exact method name string
101and a file containing the raw bytes to be sent on the wire
102
103```
Yang Gao0aa822b2016-06-09 17:23:38 -0700104$ bins/opt/grpc_cli call localhost:50051 /helloworld.Greeter/SayHello --input_binary_file=input.bin \
Yang Gaoac4b3a62016-06-08 15:00:25 -0700105 --output_binary_file=output.bin
106```
107On success, you will need to read or decode the response from the `output.bin` file.