Contents

connectrpc/connect-swift

The Swift implementation of Connect: Protobuf RPC that works.

Code Generation

This repo includes a code generator, protoc-gen-connect-swift, that works in tandem with Apple's [proto-gen-swift][swift-protobuf]. The latter generates types that correspond to the various message and enum types; the former generates RPC client stubs that use this runtime library to implement RPCs.

You can start generating code with buf by adding a stanza like the following to your buf.gen.yaml configuration:

 version: v2
 plugins:
   - remote: buf.build/apple/swift
     out: Generated
     opt: Visibility=Public
+  - remote: buf.build/connectrpc/swift
+    out: Generated
+    opt:
+      - GenerateAsyncMethods=true
+      - GenerateCallbackMethods=true
+      - Visibility=Public

You can read more about using buf as well as read more about the various options in the [documentation][generation-docs].

To use protoc instead of buf, add a --connect-swift_out flag to protoc invocations, like so:

-protoc --swift_out=. --swift_opt=Visibility=Public my.proto
+protoc --swift_out=. --connect-swift_out=. \
+    --swift_opt=Visibility=Public \
+    --connect-swift_opt=GenerateAsyncMethods=true,GenerateCallbackMethods=true,Visibility=Public \
+    my.proto

Quick Start

Head over to our [quick start tutorial][getting-started] to get started. It only takes ~10 minutes to complete a working SwiftUI chat app that uses Connect-Swift!

Documentation

Comprehensive documentation for everything, including [interceptors][interceptors], [mocking/testing][testing], [streaming][streaming], and [error handling][error-handling] is available on the [connectrpc.com website][getting-started].

Example Apps

Example apps are available in the Examples directory and can be opened and built using Xcode. They demonstrate:

  • Using streaming APIs
  • Integrating with Swift Package Manager
  • Integrating with CocoaPods
  • Using the [Connect protocol][connect-protocol]
  • Using the [gRPC protocol][grpc-protocol]
  • Using the [gRPC-Web protocol][grpc-web-protocol]

Contributing

We'd love your help making Connect better!

Extensive instructions for building the library and generator plugins locally, running tests, and contributing to the repository are available in our CONTRIBUTING.md guide. Please check it out for details.

Ecosystem

  • [connect-kotlin][connect-kotlin]: Idiomatic gRPC & Connect RPCs for Kotlin
  • [connect-go][connect-go]: Go service stubs for servers
  • [connect-es][connect-es]: Type-safe APIs with Protobuf and TypeScript
  • [Buf Studio][buf-studio]: Web UI for ad-hoc RPCs
  • [conformance][connect-conformance]: Connect, gRPC, and gRPC-Web

interoperability tests

Status

This project is stable and follows semantic versioning, which means any breaking changes will result in a major version increase. Our goal is to not make breaking changes unless absolutely necessary.

Package Metadata

Repository: connectrpc/connect-swift

Homepage: https://connectrpc.com

Stars: 148

Forks: 39

Open issues: 3

Default branch: main

Primary language: swift

License: Apache-2.0

Topics: api, api-client, connectrpc, grpc, protobuf, rpc, swift

README: README.md