diff --git a/docs/_docs/grpcapiconfiguration.md b/docs/_docs/grpcapiconfiguration.md index 2c358630565..a3b59703f37 100644 --- a/docs/_docs/grpcapiconfiguration.md +++ b/docs/_docs/grpcapiconfiguration.md @@ -1,17 +1,34 @@ --- -title: Usage without annotations (gRPC API Configuration) +title: Usage without annotations category: documentation order: 100 --- # gRPC API Configuration -In some sitations annotating the .proto file of a service is not an option. For example you might not have control over the .proto file or you might want to expose the same gRPC API multiple times in completely different ways. +In some situations annotating the .proto file of a service is not an option. For example, you might not have control over the .proto file, or you might want to expose the same gRPC API multiple times in completely different ways. +`grpc-gateway` supports 2 ways of dealing with these situations: + +* [use the `generate_unbound_methods` option](#generate_unbound_methods) +* [provide an external configuration file](#using-an-external-configuration-file) (gRPC API Configuration) + +## `generate_unbound_methods` + +Providing this parameter to the protoc plugin will make it produce the HTTP mapping even for methods without any `HttpRule` annotation. +This is similar to how [Cloud Endpoints behaves](https://cloud.google.com/endpoints/docs/grpc/transcoding#where_to_configure_transcoding) and uses the way [gRPC itself](https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md) maps to HTTP/2: + +* HTTP method is `POST` +* URI path is built from the service's name and method: `//` (e.g.: `/my.package.EchoService/Echo`) +* HTTP body is the serialized protobuf message. + +NOTE: the same option is also supported by the `gen-swagger` plugin. + +## Using an external configuration file Google Cloud Platform offers a way to do this for services hosted with them called ["gRPC API Configuration"](https://cloud.google.com/endpoints/docs/grpc/grpc-service-config). It can be used to define the behavior of a gRPC API service without modifications to the service itself in the form of [YAML](https://en.wikipedia.org/wiki/YAML) configuration files. grpc-gateway generators implement the [HTTP rules part](https://cloud.google.com/endpoints/docs/grpc-service-config/reference/rpc/google.api#httprule) of this specification. This allows you to take a completely unannotated service proto file, add a YAML file describing its HTTP endpoints and use them together like a annotated proto file with the grpc-gateway generators. -## Usage of gRPC API Configuration YAML files +### Usage of gRPC API Configuration YAML files The following is equivalent to the basic [usage example](usage.html) but without direct annotation for grpc-gateway in the .proto file. Only some steps require minor changes to use a gRPC API Configuration YAML file instead: 1. Define your service in gRPC as usual