Skip to content

Latest commit

 

History

History
52 lines (34 loc) · 1.05 KB

README.md

File metadata and controls

52 lines (34 loc) · 1.05 KB

Swift gRPC

A very simple gRPC library to use with Apple's swift-protobuf.


⚠️ There is active work going on here that will result in API changes. ⚠️


Usage

Protobuf outline:

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 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:

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