blob: 79a131c041a969bd4166d1b4e05a2a77bc8210e1 [file] [log] [blame] [view]
Yang Gaoac4b3a62016-06-08 15:00:25 -07001# gRPC command line tool
2
3## Overview
4
5This document describes the command line tool that comes with gRPC repository. It is desireable to have command line
6tools written in other languages to roughly follow the same syntax and flags.
7
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
Yang Gao0aa822b2016-06-09 17:23:38 -070033To use the tool, you need to get the grpc repository and in the grpc directory execute
Yang Gaoac4b3a62016-06-08 15:00:25 -070034
35```
Yang Gao0aa822b2016-06-09 17:23:38 -070036$ make grpc_cli
Yang Gaoac4b3a62016-06-08 15:00:25 -070037```
38
39The main file can be found at
40https://github.com/grpc/grpc/blob/master/test/cpp/util/grpc_cli.cc
41
42## Usage
43
44### Basic usage
45
46Send a rpc to a helloworld server at `localhost:50051`:
47
48```
Yuchen Zeng9cb94452016-07-20 16:39:31 -070049$ bins/opt/grpc_cli call localhost:50051 SayHello "name: 'world'" \
50 --enable_ssl=false
Yang Gaoac4b3a62016-06-08 15:00:25 -070051```
52
53On success, the tool will print out
54
55```
56Rpc succeeded with OK status
Yuchen Zeng9cb94452016-07-20 16:39:31 -070057Response:
Yang Gaoac4b3a62016-06-08 15:00:25 -070058 message: "Hello world"
59```
60
61The `localhost:50051` part indicates the server you are connecting to. `SayHello` is (part of) the
Yuchen Zeng9cb94452016-07-20 16:39:31 -070062gRPC method string. Then `"name: 'world'"` is the text format of the request proto message. We are
63not using ssl here by `--enable_ssl=false`. For information on more flags, look at the comments of `grpc_cli.cc`.
64
65### Use local proto files
66
67If the server does not have the server reflection service, you will need to provide local proto
68files containing the service definition. The tool will try to find request/response types from
69them.
70
71```
72$ bins/opt/grpc_cli call localhost:50051 SayHello "name: 'world'" \
73 --protofiles=examples/protos/helloworld.proto --enable_ssl=false
74```
75
76If the proto files is not under current directory, you can use `--proto_path` to specify a new
77search root.
Yang Gaoac4b3a62016-06-08 15:00:25 -070078
79### Send non-proto rpc
80
81For using gRPC with protocols other than probobuf, you will need the exact method name string
82and a file containing the raw bytes to be sent on the wire
83
84```
Yang Gao0aa822b2016-06-09 17:23:38 -070085$ bins/opt/grpc_cli call localhost:50051 /helloworld.Greeter/SayHello --input_binary_file=input.bin \
Yang Gaoac4b3a62016-06-08 15:00:25 -070086 --output_binary_file=output.bin
87```
88On success, you will need to read or decode the response from the `output.bin` file.