How to Code With Swift on the Server
Since Apple first introduced Swift as the successor to Objective-C, it has revolutionized how the community codes iOS, macOS, watchOS and tvOS apps. When Swift became an open-source platform, it opened new possibilities for the language beyond mobile and client-side apps—Swift became a server language too! In this tutorial, you'll learn what server-side Swift is and why you would want to have Swift on your back-end.
The server-side Swift initiative is being pushed by three prominent projects—Vapor by Qutheory, IBM’s Kitura, and Perfect—with the goal of letting Swift developers create fully fledged back-end services. This, in essence, will transform such developers into full-stack developers, negating the need for reliance on Node or PHP or giving control to a BaaS platform such as Google’s Firebase.
Objectives of This Article
In this article, you will learn all about server-side Swift. First I'll explain how server-side Swift works, and then I'll show you how to get started with the Kitura, Vapor, and Perfect frameworks.
What Is Server-Side Swift?
Swift was first announced by Apple in 2014 and quickly became one of the fastest-growing programming languages. Swift draws from many of the best contemporary languages, such as Python, allowing elegance and ease of use. It frees engineers from the technical shackles of Objective-C, allowing more fluid and intuitive work.
In December 2015, Apple made another monumental announcement and made the Swift language—along with its supporting libraries, debugger, and package manager—an open-source project under the Apache 2.0 license, opening up the platform for the public to create pull requests and contribute. The shift away from Objective-C has not only enticed the many Objective-C developers contributing to the App Store, but it has made it easier for developers of all skills and backgrounds to enter the Apple ecosystem with Swift.
However, while Apple’s development tools have historically made it easier for developers to create visually compelling and engaging apps for the App Store, one notable bottleneck has been that projects still needed specialized back-end developers to create complex data-driven applications. So iOS and macOS developers would either need to engage the assistance of a Python, PHP or Node developer to create their back-end database or pick up the skill themselves, resulting in a significantly heavier workload to complete their project objectives.
Although back-end-as-a-service (BaaS) has come to the rescue of iOS developers, with no-code back-end solutions such as Google’s Firebase and Apple’s very own CloudKit which alleviate the complexities of the back-end, many teams and projects demand more. This is where server-side Swift comes in, allowing you to create a fully fledged multi-threaded back-end server that is open-sourced and infinitely configurable.
Server-side Swift lets you choose how you host your back-end server, whether with AWS, RackSpace, or your own physical servers. You can also choose how to load balance your servers (e.g. via popular server solutions such as NGINX) and how to persist your data in a database (be it NoSQL solutions such as MongoDB, or traditional databases such as Postgres, MySQL, or Oracle). Not only that, but you are never tied to one component solution—you can switch up without affecting your entire app codebase.
The point is that by opting for an open-source server-side Swift solution such as Vapor by Qutheory, IBM’s Kitura, or Perfect, you take advantage of a vast array of plugins that allow you to configure your back end just the way you want it, making use of your existing team’s skill set in Swift to do so.
Server-side Swift certainly sounds compelling, but which framework is right for you? Next we take a look at each one in turn, starting with Kitura.