https://github.com/nathanborror/swift-grpc
🔮 A very simple gRPC library to use with Apple's swift-protobuf.
https://github.com/nathanborror/swift-grpc
Last synced: 8 months ago
JSON representation
🔮 A very simple gRPC library to use with Apple's swift-protobuf.
- Host: GitHub
- URL: https://github.com/nathanborror/swift-grpc
- Owner: nathanborror
- Created: 2016-10-01T04:28:31.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-24T21:12:50.000Z (almost 9 years ago)
- Last Synced: 2025-04-08T08:06:42.126Z (9 months ago)
- Language: Swift
- Homepage:
- Size: 30.3 KB
- Stars: 30
- Watchers: 4
- Forks: 10
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Swift gRPC
A very simple [gRPC][1] library to use with Apple's [swift-protobuf][2].
---
:warning: There is active work going on here that will result in API changes. :warning:
---
## Usage
Protobuf outline:
```protobuf
syntax = "proto3";
service HelloService {
rpc Send(HelloRequest) returns (HelloResponse) {}
}
message HelloRequest {
string text = 1;
}
message HelloResponse {
string text = 1;
}
```
Build protobuf file with [swift-protobuf-plugin](https://github.com/apple/swift-protobuf-plugin) and whatever server-side plugin of your choosing, here I'm using Go:
$ protoc --swift_out=YourSwiftClient/Sources --go_out=plugins=grpc:. your-protobuf-file.proto
Client code:
```swift
import Foundation
let url = URL(string: "http://localhost:8080")!
let session = GrpcSession(url: url)
let hello = HelloRequest(text: "Hello, World")
try? session.write(path: "/HelloService/Send", data: hello) { bytes in
let resp = try? HelloResponse(protobufBytes: bytes)
print(resp)
}
```
[1]:http://www.grpc.io
[2]:https://github.com/apple/swift-protobuf