Publish events to server-side Swift applications with the new Channels SDK

Swift-server-SDK.png

Use of server-side Swift has become more widespread in recent years. Our new Swift server SDK will allow you to trigger events and fetch realtime information on your Swift server apps.

Introduction

Pusher offers several official server libraries for interacting with the Channels HTTP API. Though the Swift Channels client SDK has existed for several years, a companion Swift server SDK has not been offered before now.

Use of server-side Swift has become more widespread in recent years. Popular frameworks like Vapor and Kitura are making it easy to develop fully-fledged server applications written in Swift. The Swift server workgroup is active and Swift is supported on several Linux distributions which means that developers have a lot of flexibility when it comes to hosting these server applications.

With all this in mind, we recently completed a project to build a new Swift library for the Channels HTTP API so you can now use Channels to trigger events and fetch information on your server applications written in server-side Swift.

A Swift library for the Channels HTTP API

The brief for the new Channels Swift server library was a simple one:

  • The new library will offer all the same features as the other server libraries
  • The public API will be as consistent as possible with the APIs of the other server libraries
  • The new library will be a modern and robust Swift interface to the Channels HTTP API

Features

The new Swift library offers the same feature set as the other server libraries. This includes:

Public API

The public API of the new library is consistent with the other server libraries, whilst leveraging language features of Swift 5. The public API is fully documented using the Apple Quick Help documentation comments syntax. The API documentation is automatically generated using Jazzy and is self-hosted by the GitHub repository.

Architectural approach

The new library makes use of several best practices for a modern Swift SDK. For example, we combined a protocol-oriented programming approach with dependency injection techniques, which allows unit testing coverage to be much more comprehensive. The tests themselves are also easier to maintain and iterate on.

We built the library using a modular approach, where components such as the networking layer exist as discrete services. The library is easy to maintain, so we are very well placed to improve Channels with new features in the future.

Applications

The primary use case for this new library is server-side Swift applications (which are most often hosted on a Linux based platform). However, the library itself has no specific platform restrictions and therefore supports iOS, macOS, tvOS and watchOS. This is useful if you wish to interact with the Channels HTTP API from an application running on Apple hardware devices.

Availability

The new Channels Swift server SDK is available in beta (v0.1.0) now. It is completely open-source just like the other server and client libraries that Pusher offers.

If you are interested in building server-side Swift applications with Channels we encourage you to start using the beta now. The library is already feature-complete and any changes needed to the public API should be minor. As with any software beta, if you encounter a bug please open an issue on the GitHub repository.