George Barnett 2ed95d8573 Update dependency requirements and docs (#2188) vor 10 Monaten
..
Sources 9639fe95bd Use the protoc build plugin in examples (#2171) vor 10 Monaten
.gitignore 5be11cd938 Add reflection server example (#2149) vor 11 Monaten
Package.swift 2ed95d8573 Update dependency requirements and docs (#2188) vor 10 Monaten
README.md bfe033fbdd Update Example READMEs (#2179) vor 10 Monaten

README.md

Reflection Server

This example demonstrates the gRPC Reflection service which is described in more detail in the gRPC documentation.

Overview

A 'reflection-server' command line tool that uses the reflection service implementation from grpc/grpc-swift-extras and the Echo service (see the 'echo' example).

The reflection service requires you to initialize it with a set of Protobuf file descriptors for the services you're offering. You can use protoc to create a descriptor set including dependencies and source information for each service.

The following command will generate a descriptor set at path/to/output.pb from the path/to/input.proto file with source information and any imports used in input.proto:

protoc --descriptor_set_out=path/to/output.pb path/to/input.proto \
  --include_source_info \
  --include_imports

Prerequisites

You must have the Protocol Buffers compiler (protoc) installed. You can find the instructions for doing this in the gRPC Swift Protobuf documentation. The swift commands below are all prefixed with PROTOC_PATH=$(which protoc), this is to let the build system know where protoc is located so that it can generate stubs for you. You can read more about it in the gRPC Swift Protobuf documentation.

Usage

Build and run the server using the CLI:

$ swift run reflection-server
Reflection server listening on [ipv4]127.0.0.1:31415

You can use 'grpcurl' to query the reflection service. If you don't already have it installed follow the instructions in the 'grpcurl' project's README.

You can list all services with:

$ grpcurl -plaintext 127.0.0.1:31415 list
echo.Echo

And describe the 'Get' method in the 'echo.Echo' service:

$ grpcurl -plaintext 127.0.0.1:31415 describe echo.Echo.Get
echo.Echo.Get is a method:
// Immediately returns an echo of a request.
rpc Get ( .echo.EchoRequest ) returns ( .echo.EchoResponse );

You can also call the 'echo.Echo.Get' method:

$ grpcurl -plaintext -d '{ "text": "Hello" }' 127.0.0.1:31415 echo.Echo.Get
{
  "text": "Hello"
}