gRPC-swagger

Build Status Coverage Status GitHub license

中文文档

What is gRPC-swagger

gRPC-swagger is a gRPC debuggling tool developed based on gRPC reflection. It can be used to list and call gRPC methods using swagger-ui conveniently. As gRPC-swagger is based on gRPC reflection, you only need to enable reflection feature when starting the service and no need modifying proto files and related code implementations.

Feature List

Screenshots

Live Demo

demo

Build and Run

Use released jar

wget https://github.com/grpc-swagger/grpc-swagger/releases/latest/download/grpc-swagger.jar 
java -jar grpc-swagger.jar

Build from source

mvn clean package
java -jar grpc-swagger-web/target/grpc-swagger.jar

By default it will start at port 8080, use --server.port=yourport if you want to use another port.

java -jar grpc-swagger-web/target/grpc-swagger.jar --server.port=8888

Other parameters

How to use it

  1. Run gRPC-swagger, referring to Build and Run
  2. Enable reflection when staring service. Below is a java example:
    add dependency to pom.xml:
    <dependency>
       <groupId>io.grpc</groupId>
       <artifactId>grpc-services</artifactId>
       <version>${grpc.version}</version>
    </dependency>

    enable reflection:

    Server server = ServerBuilder.forPort(SERVER_PORT)
       .addService(new HelloServiceImpl())
       .addService(ProtoReflectionService.newInstance())
       .build()
       .start();
  3. Register endpoint. Open this page, input necessary message and click register button, gRPC-swagger will automatically scan available services and return successful registered services when finished. You can click service link jump to ui page.

  1. Use swagger-ui to see gRPC services.
  2. Click Try it out button to have a test on the gRPC method.

Parameters

API

Register Endpoint

url:/register

parameters:

return example:

{
    "code": 1,
    "data": [
        {
            "service": "io.grpc.grpcswagger.showcase.HelloService",
            "endPoint": "localhost:12347"
        }
    ]
}

Services List

url: /listServices

return example:

{
    "code": 1,
    "data": [
        {
            "service": "io.grpc.grpcswagger.showcase.HelloService",
            "endPoint": "localhost:12347"
        }
    ]
}

Call gRPC Method

url: /{rawFullMethodName}

parameters:

Swagger API

url: /v2/api-docs

return data used by swagger-ui

parameters:

Acknowledgment

Thanks to the polyglot project,The reflection related logic in our project is modified on polygolt.

Contribute

Feel free to open an issue or pull request. We will appreciate it!

FAQ

License

MIT License.