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=PublicYou 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.protoQuick 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.
Legal
Offered under the Apache 2 license.
[blog]: https://buf.build/blog/announcing-connect-swift [buf-studio]: https://buf.build/studio [connect-conformance]: https://github.com/connectrpc/conformance [connect-go]: https://github.com/connectrpc/connect-go [connect-kotlin]: https://github.com/connectrpc/connect-kotlin [connect-protocol]: https://connectrpc.com/docs/protocol [connect-es]: https://github.com/connectrpc/connect-es [error-handling]: https://connectrpc.com/docs/swift/errors [generation-docs]: https://connectrpc.com/docs/swift/generating-code [getting-started]: https://connectrpc.com/docs/swift/getting-started [grpc-protocol]: https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md [grpc-web-protocol]: https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-WEB.md [interceptors]: https://connectrpc.com/docs/swift/interceptors [protobuf]: https://developers.google.com/protocol-buffers [slack]: https://buf.build/links/slack [streaming]: https://connectrpc.com/docs/swift/using-clients#using-generated-clients [swift-pm-integration]: https://connectrpc.com/docs/swift/getting-started#add-the-connect-swift-package [swift-protobuf]: https://github.com/apple/swift-protobuf [testing]: https://connectrpc.com/docs/swift/testing
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