Yang Gao | ac4b3a6 | 2016-06-08 15:00:25 -0700 | [diff] [blame] | 1 | # gRPC command line tool |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | This document describes the command line tool that comes with gRPC repository. It is desireable to have command line |
| 6 | tools written in other languages to roughly follow the same syntax and flags. |
| 7 | |
| 8 | At this point, the tool needs to be built from source, and it should be moved out to grpc-tools repository as a stand |
| 9 | alone application once it is mature enough. |
| 10 | |
Yang Gao | 0aa822b | 2016-06-09 17:23:38 -0700 | [diff] [blame] | 11 | ## Core functionality |
Yang Gao | ac4b3a6 | 2016-06-08 15:00:25 -0700 | [diff] [blame] | 12 | |
| 13 | The 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 | |
| 24 | The 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 Gao | 0aa822b | 2016-06-09 17:23:38 -0700 | [diff] [blame] | 33 | To use the tool, you need to get the grpc repository and in the grpc directory execute |
Yang Gao | ac4b3a6 | 2016-06-08 15:00:25 -0700 | [diff] [blame] | 34 | |
| 35 | ``` |
Yang Gao | 0aa822b | 2016-06-09 17:23:38 -0700 | [diff] [blame] | 36 | $ make grpc_cli |
Yang Gao | ac4b3a6 | 2016-06-08 15:00:25 -0700 | [diff] [blame] | 37 | ``` |
| 38 | |
| 39 | The main file can be found at |
| 40 | https://github.com/grpc/grpc/blob/master/test/cpp/util/grpc_cli.cc |
| 41 | |
| 42 | ## Usage |
| 43 | |
| 44 | ### Basic usage |
| 45 | |
| 46 | Send a rpc to a helloworld server at `localhost:50051`: |
| 47 | |
| 48 | ``` |
Yang Gao | 0aa822b | 2016-06-09 17:23:38 -0700 | [diff] [blame] | 49 | $ bins/opt/grpc_cli call localhost:50051 SayHello examples/protos/helloworld.proto \ |
Yang Gao | ac4b3a6 | 2016-06-08 15:00:25 -0700 | [diff] [blame] | 50 | "name: 'world'" --enable_ssl=false |
| 51 | ``` |
| 52 | |
| 53 | On success, the tool will print out |
| 54 | |
| 55 | ``` |
| 56 | Rpc succeeded with OK status |
| 57 | Response: |
| 58 | message: "Hello world" |
| 59 | ``` |
| 60 | |
| 61 | The `localhost:50051` part indicates the server you are connecting to. `SayHello` is (part of) the |
| 62 | gRPC method string. Then there is the path to the proto file containing the service definition, |
| 63 | if 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. |
| 65 | We are not using ssl here by `--enable_ssl=false`. For information on more |
| 66 | flags, look at the comments of `grpc_cli.cc`. |
| 67 | |
| 68 | ### Send non-proto rpc |
| 69 | |
| 70 | For using gRPC with protocols other than probobuf, you will need the exact method name string |
| 71 | and a file containing the raw bytes to be sent on the wire |
| 72 | |
| 73 | ``` |
Yang Gao | 0aa822b | 2016-06-09 17:23:38 -0700 | [diff] [blame] | 74 | $ bins/opt/grpc_cli call localhost:50051 /helloworld.Greeter/SayHello --input_binary_file=input.bin \ |
Yang Gao | ac4b3a6 | 2016-06-08 15:00:25 -0700 | [diff] [blame] | 75 | --output_binary_file=output.bin |
| 76 | ``` |
| 77 | On success, you will need to read or decode the response from the `output.bin` file. |