diff --git a/docs/root/configuration/http_filters/grpc_json_transcoder_filter.rst b/docs/root/configuration/http_filters/grpc_json_transcoder_filter.rst index 471297286a125..cfeb5dd61789e 100644 --- a/docs/root/configuration/http_filters/grpc_json_transcoder_filter.rst +++ b/docs/root/configuration/http_filters/grpc_json_transcoder_filter.rst @@ -11,6 +11,13 @@ This is a filter which allows a RESTful JSON API client to send requests to Envo and get proxied to a gRPC service. The HTTP mapping for the gRPC service has to be defined by `custom options `_. +JSON mapping +------------ + +The protobuf to JSON mapping is defined `here `_. For +gRPC stream request parameters, Envoy expects an array of messages, and it returns an array of messages for stream +response parameters. + .. _config_grpc_json_generate_proto_descriptor_set: How to generate proto descriptor set @@ -74,4 +81,62 @@ as its output message type. The implementation needs to set `content_type `_ (which sets the value of the HTTP response `Content-Type` header) and `data `_ -(which sets the HTTP response body) accordingly. \ No newline at end of file +(which sets the HTTP response body) accordingly. + + +Sample Envoy configuration +-------------------------- + +Here's a sample Envoy configuration that proxies to a gRPC server running on localhost:50051. Port 51051 proxies +gRPC requests and uses the gRPC-JSON transcoder filter to provide the RESTful JSON mapping. I.e., you can make either +gRPC or RESTful JSON requests to localhost:51051. + +.. code-block:: yaml + + admin: + access_log_path: /tmp/admin_access.log + address: + socket_address: { address: 0.0.0.0, port_value: 9901 } + + static_resources: + listeners: + - name: listener1 + address: + socket_address: { address: 0.0.0.0, port_value: 51051 } + filter_chains: + - filters: + - name: envoy.http_connection_manager + config: + stat_prefix: grpc_json + codec_type: AUTO + route_config: + name: local_route + virtual_hosts: + - name: local_service + domains: ["*"] + routes: + - match: { prefix: "/" } + route: { cluster: grpc, timeout: { seconds: 60 } } + http_filters: + - name: envoy.grpc_json_transcoder + config: + proto_descriptor: "/tmp/envoy/proto.pb" + services: ["HelloWorld"] + print_options: + add_whitespace: true + always_print_primitive_fields: true + always_print_enums_as_ints: false + preserve_proto_field_names: false + - name: envoy.router + + clusters: + - name: grpc + connect_timeout: 1.25s + type: logical_dns + lb_policy: round_robin + dns_lookup_family: V4_ONLY + http2_protocol_options: {} + hosts: + - socket_address: + address: docker.for.mac.localhost + port_value: 50051