Skip to content

Instantly share code, notes, and snippets.

@gistlyn
Last active December 29, 2019 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gistlyn/fd8dfcf28dfcdaf75abc4b99d06e8607 to your computer and use it in GitHub Desktop.
Save gistlyn/fd8dfcf28dfcdaf75abc4b99d06e8607 to your computer and use it in GitHub Desktop.
Swift Google protoc SSL GrpcServicesClient TodoWorld Example
import Foundation
import GRPC
import NIO
import NIOSSL
do {
let configuration = ClientConnection.Configuration(
target: .hostAndPort("todoworld.servicestack.net", 50051),
eventLoopGroup: MultiThreadedEventLoopGroup(numberOfThreads: 1),
tls: .init(certificateChain: try NIOSSLCertificate.fromPEMFile("grpc.crt").map { .certificate($0) },
certificateVerification: .none) //TODO enable SSL verification
)
let client = GrpcServicesServiceClient(connection: ClientConnection(configuration: configuration))
var request = Hello()
request.name = "gRPC Swift"
let response = try client.getHello(request).response.wait().result
print(response)
} catch {
print("ERROR\n\(error)")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment