Book Image

Hands-On Server-Side Web Development with Swift

By : Angus Yeung
Book Image

Hands-On Server-Side Web Development with Swift

By: Angus Yeung

Overview of this book

This book is about building professional web applications and web services using Swift 4.0 and leveraging two popular Swift web frameworks: Vapor 3.0 and Kitura 2.5. In the first part of this book, we’ll focus on the creation of basic web applications from Vapor and Kitura boilerplate projects. As the web apps start out simple, more useful techniques, such as unit test development, debugging, logging, and the build and release process, will be introduced to readers. In the second part, we’ll learn different aspects of web application development with server-side Swift, including setting up routes and controllers to process custom client requests, working with template engines such as Leaf and Stencil to create dynamic web content, beautifying the content with Bootstrap, managing user access with authentication framework, and leveraging the Object Relational Mapping (ORM) abstraction layer (Vapor’s Fluent and Kitura’s Kuery) to perform database operations. Finally, in the third part, we’ll develop web services in Swift and build our API Gateway, microservices and database backend in a three-tier architecture design. Readers will learn how to design RESTful APIs, work with asynchronous processes, and leverage container technology such as Docker in deploying microservices to cloud hosting services such as Vapor Cloud and IBM Cloud.
Table of Contents (18 chapters)

Surveying Swift server-side frameworks

There are many Swift web frameworks that aim to bring the benefits of Swift to server-side development. We will take a quick survey of several top Swift server-side frameworks now.

Vapor

Vapor is one of the most popular frameworks, and it enjoys the support of a very active developer community. The support from a developer community means that there are a lot of releases, bug fixes, and help that can be expected. In fact, the development of Vapor has been closely following the Swift evolution development. With the launch of SwiftNIO from Apple, as well as Swift 4.1, the Vapor developer community quickly launched Vapor 3.0 (https://github.com/vapor/vapor/releases/tag/3.0.0), which adopts asynchronous and non-blocking event-driven networking stacks, alongside futures and promises throughout the framework, fully aligning with the latest technology in the Swift ecosystem.

Overall, Vapor caters for both beginner and veteran server-side Swift developers with simple and concise syntax, strong community support, and the appeal of pure Swift implementation.

Kitura

Kitura, a Swift server-side framework from IBM that is Apache 2.0 licensed, is the result of the enterprise partnership between IBM and Apple, announced in 2014. It goes without saying that the framework has a strong backing from IBM. Kitura is well integrated into IBM's cloud product offerings, including Watson and IBM Cloud. It offers native connectors for some Watson API services, and it is easy to deploy a Kitura project to Bluemix hosting platforms using Kitura CLI. On IBM's website, there are also plenty of educational resources and support for Kitura.

The Kitura framework was migrated to support Swift 4.0 in the Kitura 2.0 that was released in October 2017. In Kitura 2.5, released in August 2018, the framework also added the support of SwiftNIO (enabled using env KITURA_NIO=1 swift build). The development of Kitura follows closely with the evolution of Swift itself.

For many Swift server-side developers, Kitura is an ideal framework choice for tapping into IBM's extensive cloud technology ecosystem and developing with enterprise applications in mind.

Perfect

Perfect (https://github.com/PerfectlySoft/Perfect) stands out as a mature and powerful Swift server-side framework. The first version of Perfect was released to the public even before Apple made Swift open source in 2015. It offers a complete array of features that a software developer may need for developing a lightweight and maintainable web application. Perfect uses a high-performance asynchronous networking engine called Perfect-Net (https://github.com/PerfectlySoft/Perfect-Net), supports secure sockets layer encryption, and adds the option for WebSockets and iOS push notifications that are commonly required by internet servers. Perfect even provides a macOS desktop application, Perfect Assistant, to help server-side developers with the deployment of their Perfect projects to AWS and Google Cloud.

We see Perfect as a good choice for Swift server-side developers who are looking for a mature and well-balanced framework for developing a scalable and solid web application.