Skip to content

Commit

Permalink
update documentation (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktr0731 authored May 3, 2020
1 parent 1e8b768 commit bcfbe90
Showing 1 changed file with 106 additions and 13 deletions.
119 changes: 106 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ So, you can format it by any commands like `jq`. Also, if you want to use the sa
- [Server streaming RPC](#server-streaming-rpc)
- [Bidirectional streaming RPC](#bidirectional-streaming-rpc)
- [Skip the rest of fields](#skip-the-rest-of-fields)
- [Enriched response](#enriched-response)
- [Usage (CLI)](#usage-cli)
- [Basic usage](#basic-usage-1)
- [Repeated fields](#repeated-fields-1)
Expand All @@ -55,6 +56,7 @@ So, you can format it by any commands like `jq`. Also, if you want to use the sa
- [Client streaming RPC](#client-streaming-rpc-1)
- [Server streaming RPC](#server-streaming-rpc-1)
- [Bidirectional streaming RPC](#bidirectional-streaming-rpc-1)
- [Enriched response](#enriched-response-1)
- [Other features](#other-features)
- [gRPC-Web](#grpc-web)
- [Supported IDL (interface definition language)](#supported-idl-interface-definition-language)
Expand Down Expand Up @@ -175,9 +177,6 @@ To show more description of a message:

Set headers for each request:
```
> header -h
usage: header <key>=<value>[, <key>=<value>...]
> header foo=bar
```

Expand All @@ -192,6 +191,8 @@ To show headers:
+-------------+-------+
```

Note that if you want to set comma-included string to a header value, it is required to specify `--raw` option.

To remove the added header:
```
> header foo
Expand Down Expand Up @@ -381,11 +382,64 @@ message Request {
In this case, REPL prompts `full_name.first_name` automatically. To skip `full_name` itself, we can use `--dig-manually` option.
It asks whether dig down a message field when the prompt encountered it.

### Enriched response
To display more enriched response, you can use `--enrich` option.

```
> call --enrich Unary
name (TYPE_STRING) => ktr
content-type: application/grpc
header_key1: header_val1
header_key2: header_val2
{
"message": "hello, ktr"
}
trailer_key1: trailer_val1
trailer_key2: trailer_val2
code: OK
number: 0
message: ""
```

## Usage (CLI)
### Basic usage
CLI mode also has some commands.

`list` command provides gRPC service inspection against to the gRPC server.

``` sh
$ evans -r cli list
api.Example
grpc.reflection.v1alpha.ServerReflection
```

If an service name is specified, it displays methods belonging to the service.

``` sh
$ evans -r cli list api.Example
api.Example.Unary
api.Example.UnaryBytes
api.Example.UnaryEnum
...
```

`desc` command describes the passed symbol (service, method, message, and so on).

``` sh
api.Example:
service Example {
rpc Unary ( .api.SimpleRequest ) returns ( .api.SimpleResponse );
rpc UnaryBytes ( .api.UnaryBytesRequest ) returns ( .api.SimpleResponse );
rpc UnaryEnum ( .api.UnaryEnumRequest ) returns ( .api.SimpleResponse );
...
}
```

`call` command invokes a method.
You can input requests from `stdin` or files.
Unlike REPL mode, you need to specify `--package`, `--service` and the method you want to call.
If gRPC server enables gRPC reflection, `--package` is unnecessary. (instead, `-r` requires)

Use `--file` (`-f`) to specify a file.
``` sh
Expand All @@ -394,15 +448,24 @@ $ cat request.json
"name": "ktr"
}

$ evans --service Example cli --call --file request.json Unary
$ evans --proto api/api.proto cli call --file request.json api.Example.Unary
{
"message": "hello, ktr"
}
```

If gRPC reflection is enabled, `--reflection` (`-r`) is available instead of specifying proto files.

``` sh
$ evans -r cli call --file request.json api.Example.Unary
{
"message": "hello, ktr"
}
```

Use `stdin`.
``` sh
$ echo '{ "name": "ktr" }' | evans --service Example cli --call Unary
$ echo '{ "name": "ktr" }' | evans cli call api.Example.Unary
{
"message": "hello, ktr"
}
Expand All @@ -419,17 +482,24 @@ service = "Example"

Then, the command will be more clear.

``` sh
$ echo '{ "name": "ktr" }' | evans cli call Unary
{
"message": "hello, ktr"
}
```

### Repeated fields
``` sh
$ echo '{ "name": ["foo", "bar"] }' | evans -r --service Example cli --call UnaryRepeated
$ echo '{ "name": ["foo", "bar"] }' | evans -r cli call api.Example.UnaryRepeated
{
"message": "hello, foo, bar"
}
```

### Enum fields
``` sh
$ echo '{ "gender": 0 }' | evans -r --service Example cli --call UnaryEnum
$ echo '{ "gender": 0 }' | evans -r cli call api.Example.UnaryEnum
{
"message": "M"
}
Expand All @@ -442,20 +512,20 @@ This constraint is come from Go's standard package [encoding/json](https://golan
$ echo 'Foo' | base64
Rm9vCg==

$ echo '{"data": "Rm9vCg=="}' | evans -r --service Example cli --call UnaryBytes
$ echo '{"data": "Rm9vCg=="}' | evans -r cli call api.Example.UnaryBytes
```

### Client streaming RPC
``` sh
$ echo '{ "name": "ktr" } { "name": "ktr" }' | evans -r --service Example cli --call ClientStreaming
$ echo '{ "name": "ktr" } { "name": "ktr" }' | evans -r cli call api.Example.ClientStreaming
{
"message": "ktr, you greet 2 times."
}
```

### Server streaming RPC
``` sh
$ echo '{ "name": "ktr" }' | evans -r --service Example cli --call ServerStreaming
$ echo '{ "name": "ktr" }' | evans -r cli call api.Example.ServerStreaming
{
"message": "hello ktr, I greet 0 times."
}
Expand All @@ -471,7 +541,7 @@ $ echo '{ "name": "ktr" }' | evans -r --service Example cli --call ServerStreami

### Bidirectional streaming RPC
``` sh
$ echo '{ "name": "foo" } { "name": "bar" }' | evans -r --service Example cli --call BidiStreaming
$ echo '{ "name": "foo" } { "name": "bar" }' | evans -r cli call api.Example.BidiStreaming
{
"message": "hello foo, I greet 0 times."
}
Expand All @@ -493,6 +563,29 @@ $ echo '{ "name": "foo" } { "name": "bar" }' | evans -r --service Example cli --
}
```

### Enriched response
To display more enriched response, you can use `--enrich` option.

```
$ echo '{"name": "ktr"}' | evans -r cli call --enrich api.Example.Unary ~/.ghq/src/github.com/ktr0731/grpc-test master
content-type: application/grpc
header_key1: header_val1
header_key2: header_val2
{
"message": "hello, ktr"
}
trailer_key1: trailer_val1
trailer_key2: trailer_val2
code: OK
number: 0
message: ""
```

JSON output is also available with `--json` option.

## Other features
### gRPC-Web
Evans also support gRPC-Web protocol.
Expand Down

0 comments on commit bcfbe90

Please sign in to comment.