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)

Reviewing source code in Vapor boilerplate

The following diagram gives you an overview of the boilerplate generated from Vapor's default template:

The Package.swift is used by Swift Package Manager during build time to configure your project's package. The package description comprises essential information such as application name, dependencies on other packages, and different build targets supported in your project.

There are three modules in the project: helloWorld, App, and AppTests. (The diagram only shows the helloWorld and App modules, but the AppTests module will be soon reviewed in the next chapter.) The functions and classes in the files in helloWorld and App modules are invoked in the following order:

  1. The helloWorld executable contains a single entry point in main.swift that calls app() to create an application instance and invokes the instance's run...