API Gateway
A native and easy gateway to provide RESTful API for gRPC, inspired by grpc-gateway, but fully automatic.
Prepare:
- Download&&Install golang/protoc/docker and Env setting.
Usage:
- Get code: [git clone https://github.com/jmzwcn/api-gateway.git];
- Tell your services in Makefile;
- "make run";
- Try the URL in your proto.
How to define RESTful in *.proto: [custom option]
your_service.proto:
syntax = "proto3";
package example;
+
+import "google/api/annotations.proto";
+
message StringMessage {
string value = 1;
}
service YourService {
- rpc Echo(StringMessage) returns (StringMessage) {}
+ rpc Echo(StringMessage) returns (StringMessage) {
+ option (google.api.http) = {
+ post: "/v1/example/echo"
+ body: "*"
+ };
+ }
}
Enjoy it!
Please refer to example&&Makefile, for custom setting.
有疑问加站长微信联系(非本文作者)
