Last active
April 26, 2024 22:54
-
-
Save andriitishchenko/8cc4aea53b7b385adc60966933bb2ee0 to your computer and use it in GitHub Desktop.
Revisions
-
andriitishchenko revised this gist
Apr 26, 2024 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -76,8 +76,8 @@ _ = client.sayHello(helloRequest).response.always { result in ``` More examples: - https://medium.com/@thomsmed/5-tips-when-getting-started-with-grpc-and-ios-9e4323bd6b98 - https://mtanriverdi.medium.com/grpc-call-on-ios-with-swift-ef11d3151cbf - https://gaitatzis.medium.com/building-a-grpc-client-in-ios-swift-3b0d36999678 - https://medium.com/@hardik.7091/guide-to-integrating-grpc-server-and-swift-client-32dc1a05aa8e - https://levelup.gitconnected.com/swift-grpc-577ce1a4d1b7 -
andriitishchenko revised this gist
Apr 26, 2024 . 1 changed file with 8 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@  # install protoc , protoc-gen-swift , protoc-gen-grpc-swift ``` brew install protobuf swift-protobuf grpc-swift grpcurl @@ -73,6 +75,9 @@ _ = client.sayHello(helloRequest).response.always { result in } ``` More examples: https://medium.com/@thomsmed/5-tips-when-getting-started-with-grpc-and-ios-9e4323bd6b98 https://mtanriverdi.medium.com/grpc-call-on-ios-with-swift-ef11d3151cbf https://gaitatzis.medium.com/building-a-grpc-client-in-ios-swift-3b0d36999678 https://medium.com/@hardik.7091/guide-to-integrating-grpc-server-and-swift-client-32dc1a05aa8e https://levelup.gitconnected.com/swift-grpc-577ce1a4d1b7 -
andriitishchenko revised this gist
Apr 26, 2024 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -72,3 +72,7 @@ _ = client.sayHello(helloRequest).response.always { result in } } ``` Auth example: https://gaitatzis.medium.com/building-a-grpc-client-in-ios-swift-3b0d36999678 -
andriitishchenko revised this gist
Apr 26, 2024 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,6 +12,8 @@ cd grpc && git sparse-checkout set examples # Start Python server on a localhost ``` grpc/examples/python/helloworld/greeter_server_with_reflection.py <-- Server we need cd grpc/examples/python/helloworld/ python3 -m pip install grpcio grpcio-tools grpcio-reflection python3 greeter_server_with_reflection.py @@ -24,23 +26,21 @@ grpcurl -plaintext -d '{"name": "TEST"}' localhost:50051 helloworld.Greeter.Say # Swift ``` grpc/examples/protos/helloworld.proto <-- convert it to Swift cd grpc/examples/protos/ protoc --swift_out=. --grpc-swift_out=Client=true,Server=false:. helloworld.proto ``` Import to Xcode files: - helloworld.grpc.swift - helloworld.pb.swift ``` Xcode->File->Swift Packages->Add Package Dependency https://github.com/grpc/grpc-swift ``` Add GRPC to your app target # Swift Client example -
andriitishchenko revised this gist
Apr 26, 2024 . 1 changed file with 25 additions and 21 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # install protoc , protoc-gen-swift , protoc-gen-grpc-swift ``` brew install protobuf swift-protobuf grpc-swift grpcurl ``` ### Use examples @@ -16,6 +16,10 @@ cd grpc/examples/python/helloworld/ python3 -m pip install grpcio grpcio-tools grpcio-reflection python3 greeter_server_with_reflection.py ``` ### Test the local server ``` grpcurl -plaintext -d '{"name": "TEST"}' localhost:50051 helloworld.Greeter.SayHello ``` # Swift @@ -47,24 +51,24 @@ import NIO ``` ``` let conf = ClientConnection.Configuration.default( target:.hostAndPort("localhost", 50051), eventLoopGroup: MultiThreadedEventLoopGroup(numberOfThreads: 1)) let connection: ClientConnection = ClientConnection.init(configuration: conf) let helloRequest = Helloworld_HelloRequest.with { $0.name = "Swift" } let client = Helloworld_GreeterNIOClient(channel: connection) _ = client.sayHello(helloRequest).response.always { result in switch result { case let .success(helloResponse): print(helloResponse.message) case let .failure(error): print(error) } } ``` -
andriitishchenko created this gist
Apr 26, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,70 @@ # install protoc , protoc-gen-swift , protoc-gen-grpc-swift ``` brew install protobuf swift-protobuf grpc-swift ``` ### Use examples ``` git clone --depth 1 --filter=blob:none --sparse https://github.com/grpc/grpc cd grpc && git sparse-checkout set examples ``` # Start Python server on a localhost ``` cd grpc/examples/python/helloworld/ python3 -m pip install grpcio grpcio-tools grpcio-reflection python3 greeter_server_with_reflection.py ``` # Swift ``` grpc/examples/protos/helloworld.proto cd grpc/examples/protos/ ``` ``` protoc --swift_out=. --grpc-swift_out=Client=true,Server=false:. helloworld.proto ``` Import to Xcode files: - helloworld.grpc.swift - helloworld.pb.swift ``` File->Swift Packages->Add Package Dependency https://github.com/grpc/grpc-swift ``` Add GRPC to your target # Swift Client example ``` import GRPC import NIO ``` ``` let conf = ClientConnection.Configuration.default( target:.hostAndPort("localhost", 50051), eventLoopGroup: MultiThreadedEventLoopGroup(numberOfThreads: 1)) let connection: ClientConnection = ClientConnection.init(configuration: conf) let helloRequest = Helloworld_HelloRequest.with { $0.name = "SwiftUI" } let client = Helloworld_GreeterNIOClient(channel: connection) _ = client.sayHello(helloRequest).response.always { result in switch result { case let .success(helloResponse): print(helloResponse.message) case let .failure(error): print(error) } } ```