Gus Cairo 3e75bbb6a0 Update example dependencies to point to the new beta tag (#2164) 11 months ago
..
Sources b143369c7b Update examples (#2163) 11 months ago
.gitignore 5be11cd938 Add reflection server example (#2149) 11 months ago
Package.swift 3e75bbb6a0 Update example dependencies to point to the new beta tag (#2164) 11 months ago
README.md 5be11cd938 Add reflection server example (#2149) 11 months ago

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

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"
}