blob: 89a70548b8b23306e859b76794cf92c42a290a44 [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.
18- Find the request/response types from a given proto file.
19- Read proto request in text form.
20- Read request in wire form (for protobuf messages, this means serialized binary form).
21- Display proto response in text form.
22- Write response in wire form to a file.
23
24The command line tool should support the following things:
25
26- List server services and methods through server reflection.
27- Infer request/response types from server reflection result.
28- 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```
Yang Gao0aa822b2016-06-09 17:23:38 -070049$ bins/opt/grpc_cli call localhost:50051 SayHello examples/protos/helloworld.proto \
Yang Gaoac4b3a62016-06-08 15:00:25 -070050 "name: 'world'" --enable_ssl=false
51```
52
53On success, the tool will print out
54
55```
56Rpc succeeded with OK status
57Response:
58 message: "Hello world"
59```
60
61The `localhost:50051` part indicates the server you are connecting to. `SayHello` is (part of) the
62gRPC method string. Then there is the path to the proto file containing the service definition,
63if it is not under current directory, you can use `--proto_path` to specify a new search root.
64`"name: 'world'"` is the text format of the request proto message.
65We are not using ssl here by `--enable_ssl=false`. For information on more
66flags, look at the comments of `grpc_cli.cc`.
67
68### Send non-proto rpc
69
70For using gRPC with protocols other than probobuf, you will need the exact method name string
71and a file containing the raw bytes to be sent on the wire
72
73```
Yang Gao0aa822b2016-06-09 17:23:38 -070074$ bins/opt/grpc_cli call localhost:50051 /helloworld.Greeter/SayHello --input_binary_file=input.bin \
Yang Gaoac4b3a62016-06-08 15:00:25 -070075 --output_binary_file=output.bin
76```
77On success, you will need to read or decode the response from the `output.bin` file.