11# Reflection service
22
3- This tutorial goes through the steps of adding Reflection service to a
4- server, running it and testing it using gRPCurl.
3+ This tutorial goes through the steps of adding Reflection service to a
4+ server, running it and testing it using gRPCurl.
55
6- The server used in this example is implemented at
6+ The server used in this example is implemented at
77 [ Sources/Examples/ReflectionService/ReflectionServer.swift] [ reflection-server ]
8- and it supports the "Greeter", "Echo", and "Reflection" services.
8+ and it supports the "Greeter", "Echo", and "Reflection" services.
99
1010
1111## Overview
1212
13- The Reflection service provides information about the public RPCs served by a server.
13+ The Reflection service provides information about the public RPCs served by a server.
1414It is specific to services defined using the Protocol Buffers IDL.
1515By calling the Reflection service, clients can construct and send requests to services
16- without needing to generate code and types for them.
16+ without needing to generate code and types for them.
1717
18- You can also use CLI clients such as [ gRPCurl] [ grpcurl-setup ] and the [ gRPC command line tool] [ grpc-cli ] to:
18+ You can also use CLI clients such as [ gRPCurl] [ grpcurl-setup ] and the [ gRPC command line tool] [ grpc-cli ] to:
1919- list services,
2020- describe services and their methods,
2121- describe symbols,
@@ -28,17 +28,17 @@ gRPC Swift supports both [v1][v1] and [v1alpha][v1alpha] of the reflection servi
2828
2929You can use the Reflection service by adding it as a provider when constructing your server.
3030
31- To initialise the Reflection service we will use
31+ To initialise the Reflection service we will use
3232`` GRPCReflectionService/ReflectionService/init(reflectionDataFileURLs:version:) `` .
33- It receives the URLs of the files containing the reflection data of the proto files
33+ It receives the URLs of the files containing the reflection data of the proto files
3434describing the services of the server and the version of the reflection service.
3535
3636### Generating the reflection data
3737
3838The server from this example uses the ` GreeterProvider ` and the ` EchoProvider ` ,
3939besides the ` ReflectionService ` .
4040
41- The associated proto files are located at ` Sources/Examples/HelloWorld/Model/helloworld.proto ` , and
41+ The associated proto files are located at ` Sources/Examples/HelloWorld/Model/helloworld.proto ` , and
4242` Sources/Examples/Echo/Model/echo.proto ` respectively.
4343
4444In order to generate the reflection data for the ` helloworld.proto ` , you can run the following command:
@@ -51,8 +51,8 @@ $ protoc Sources/Examples/HelloWorld/Model/helloworld.proto \
5151```
5252
5353Let's break the command down:
54- - The first argument passed to ` protoc ` is the path
55- to the ` .proto ` file to generate reflection data
54+ - The first argument passed to ` protoc ` is the path
55+ to the ` .proto ` file to generate reflection data
5656 for: [ ` Sources/Examples/HelloWorld/Model/helloworld.proto ` ] [ helloworld-proto ] .
5757- The ` proto_path ` flag is the path to search for imports: ` Sources/Examples/HelloWorld/Model ` .
5858- The 'grpc-swift_opt' flag allows us to list options for the Swift generator.
@@ -61,18 +61,18 @@ Let's break the command down:
6161 where the generated file will be located: ` Sources/Examples/ReflectionService/Generated ` .
6262
6363This command assumes that the ` protoc-gen-grpc-swift ` plugin is in your ` $PATH ` environment variable.
64- You can learn how to get the plugin from this section of the ` grpc-swift ` README:
64+ You can learn how to get the plugin from this section of the ` grpc-swift ` README:
6565https://github.com/grpc/grpc-swift#getting-the-protoc-plugins .
6666
6767The command for generating the reflection data for the ` Echo ` service is similar.
6868
69- You can use Swift Package Manager [ resources] [ swiftpm-resources ] to add the generated reflection data to your target.
70- In our example the reflection data is written into the "Generated" directory within the target
69+ You can use Swift Package Manager [ resources] [ swiftpm-resources ] to add the generated reflection data to your target.
70+ In our example the reflection data is written into the "Generated" directory within the target
7171so we include the ` .copy("Generated") ` rule in our target's resource list.
7272
73- ### Instantiating the Reflection service
73+ ### Instantiating the Reflection service
7474
75- To instantiate the ` ReflectionService ` you need to pass the URLs of the files containing
75+ To instantiate the ` ReflectionService ` you need to pass the URLs of the files containing
7676the generated reflection data and the version to use, in our case ` .v1 ` .
7777
7878Depending on the version of [ gRPCurl] [ grpcurl ] you are using you might need to use the ` .v1alpha ` instead.
@@ -84,9 +84,14 @@ reflection.
8484guard
8585 let greeterURL = Bundle.module.url (
8686 forResource : " helloworld" ,
87- withExtension : " grpc.reflection.txt"
87+ withExtension : " grpc.reflection" ,
88+ subdirectory : " Generated"
8889 ),
89- let echoURL = Bundle.module.url (forResource : " echo" , withExtension : " grpc.reflection.txt" )
90+ let echoURL = Bundle.module.url (
91+ forResource : " echo" ,
92+ withExtension : " grpc.reflection" ,
93+ subdirectory : " Generated"
94+ )
9095else {
9196 print (" The resource could not be loaded." )
9297 throw ExitCode.failure
@@ -123,7 +128,7 @@ Please follow the instructions from the [gRPCurl README][grpcurl-setup] to set u
123128From a different terminal than the one used for running the server, we will call gRPCurl commands,
124129following the format: ` grpcurl [flags] [address] [list|describe] [symbol] ` .
125130
126- We use the ` -plaintext ` flag, because the server isn't configured with TLS, and
131+ We use the ` -plaintext ` flag, because the server isn't configured with TLS, and
127132the address is set to ` localhost:1234 ` .
128133
129134
0 commit comments