https://github.com/asarkar/okgrpc
gRPC Java client and CLI
https://github.com/asarkar/okgrpc
cli grpc grpc-client grpc-java grpc-kotlin grpc-reflect protobuf protobuf-java
Last synced: about 1 year ago
JSON representation
gRPC Java client and CLI
- Host: GitHub
- URL: https://github.com/asarkar/okgrpc
- Owner: asarkar
- License: apache-2.0
- Created: 2020-11-23T14:08:42.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-12-07T23:47:33.000Z (over 5 years ago)
- Last Synced: 2025-01-13T02:18:39.238Z (about 1 year ago)
- Topics: cli, grpc, grpc-client, grpc-java, grpc-kotlin, grpc-reflect, protobuf, protobuf-java
- Language: Kotlin
- Homepage:
- Size: 207 KB
- Stars: 4
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OkGRPC
gRPC Java client and CLI based on [gRPC Server Reflection](https://github.com/grpc/grpc/blob/master/doc/server-reflection.md).
Can be used to inspect gRPC services and execute RPC methods dynamically without needing a proto file. The client can
be directly used from any JVM source code, while the CLI can be executed on command line. No installation necessary,
only needs Java 8 or later.
[](https://github.com/asarkar/okgrpc/actions?query=workflow%3A%22CI+Pipeline%22)
## CLI Usage
You can find the latest version on Bintray. [  ](https://bintray.com/asarkar/mvn/com.asarkar.grpc%3Aokgrpc-cli/_latestVersion)
It's also on jcenter.
It's an executable JAR. Run with `--help` for main CLI usage, and ` --help` for specific command usage.
> For brevity, I show `java -jar okgrpc-cli-.jar` simply as `okgrpc-cli` below.
Get all services:
```
$ okgrpc-cli -a localhost:64575 get
com.asarkar.okgrpc.test.GreetingService
grpc.reflection.v1alpha.ServerReflection
```
Describe a service:
```
$ okgrpc-cli -a localhost:64575 desc -s com.asarkar.okgrpc.test.GreetingService
name: "com/asarkar/okgrpc/test/greeting_service.proto"
package: "com.asarkar.okgrpc.test"
dependency: "com/asarkar/okgrpc/test/greeting.proto"
service {
name: "GreetingService"
method {
name: "Greet"
input_type: ".com.asarkar.okgrpc.test.GreetRequest"
output_type: ".com.asarkar.okgrpc.test.GreetResponse"
options {
}
}
// more methods elided
}
```
Describe a method:
```
$ okgrpc-cli -a localhost:64575 desc -m com.asarkar.okgrpc.test.GreetingService.Greet
name: "Greet"
input_type: ".com.asarkar.okgrpc.test.GreetRequest"
output_type: ".com.asarkar.okgrpc.test.GreetResponse"
options {
}
```
Describe a type:
```
$ okgrpc-cli -a localhost:64575 desc -t com.asarkar.okgrpc.test.GreetRequest
name: "GreetRequest"
field {
name: "greeting"
number: 1
label: LABEL_OPTIONAL
type: TYPE_MESSAGE
type_name: ".com.asarkar.okgrpc.test.Greeting"
}
```
Execute a method:
```
$ okgrpc-cli -a localhost:64575 exec \
> -h "key: value" \
> com.asarkar.okgrpc.test.GreetingService.Greet \
> '{ "greeting": { "name" : "test" } }'
{
"result": "Hello, test"
}
```
It is perfectly fine to send multiple requests for client streaming calls; each string needs to be a valid JSON
representing the Protobuf request object.
Binary data may be sent in the request as valid UTF-8 encoded string (like Base64). Of course, the server needs to
know that and decode accordingly.
It is possible to use local `.proto` files if reflection isn't enabled on the server.
```
$ okgrpc-cli -a localhost:64575 exec \
> --proto-path= \
> --proto-file= \
> com.asarkar.okgrpc.test.GreetingService.Greet \
> '{ "greeting": { "name" : "test" } }'
{
"result": "Hello, test"
}
```
## Client Usage
You can find the latest version on Bintray. [  ](https://bintray.com/asarkar/mvn/com.asarkar.grpc%3Aokgrpc-client/_latestVersion)
It's also on jcenter.
```kotlin
val client = OkGrpcClient.Builder()
.withChannel(ManagedChannelFactory.getInstance(address))
.build()
```
All the methods are defined as extension functions in the `OkGrpcClientExtn` file, that from Java, will become `static`
methods in `OkGrpcClientExtnKt` class.
See KDoc for more details.
## Contribute
This project is a volunteer effort. You are welcome to send pull requests, ask questions, or create issues.
If you like it, you can help by spreading the word!
## License
Copyright 2020 Abhijit Sarkar - Released under [Apache License v2.0](LICENSE).