Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hands-On Server-Side Web Development with Swift

You're reading from   Hands-On Server-Side Web Development with Swift Build dynamic web apps by leveraging two popular Swift web frameworks: Vapor 3.0 and Kitura 2.5

Arrow left icon
Product type Paperback
Published in Nov 2018
Publisher Packt
ISBN-13 9781789341171
Length 404 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Angus Yeung Angus Yeung
Author Profile Icon Angus Yeung
Angus Yeung
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Preface 1. Introducing Server-Side Swift FREE CHAPTER 2. Getting Started with Vapor and Kitura 3. Building Your First Web App 4. Debugging and Testing 5. Setting Up Routes and Controllers 6. Working with Template Engines 7. Bootstrapping Your Design 8. Employing Storage Framework 9. Adding Authentication 10. Understanding Technologies for Web Services 11. Designing for API Gateway 12. Deploying to the Cloud 13. Developing an iPhone Client 14. Developing Microservices 15. Vapor Boilerplate Project 16. Kitura Boilerplate Project 17. Other Books You May Enjoy

Choosing the right framework

When it comes to choosing the right Swift server-side framework to work with, we shall compare the different frameworks in terms of the several factors that follow:

  • How fast is the framework's execution performance?
  • How complete are the features that the framework offers?
  • What kind of ecosystem does the framework adopt?
  • What kind of community support is there for the framework?

Performance

Since Swift is a compiled language, server-side frameworks written in pure Swift are not necessarily slower than frameworks written in other native programming languages. However, different Swift server-side frameworks may adopt different low-level software stacks or handle events differently.

A collection of benchmarks for popular web frameworks, including both Swift and non-Swift implementations, are documented here: https://medium.com/@codevapor/vapor-3-0-0-released-8356fa619a5d. As we can see, Swift frameworks perform better than most of the web frameworks that are written in interpreted languages such as JavaScript and Python. The benchmarks were based on processing plain text and demonstrated how fast Swift can process HTTP headers. All three Swift server-side frameworks, Vapor, Perfect, and Kitura, are comparable in their performance of plain text processing.

If you are interested in evaluating different aspects of a web framework, for example, the performance for handling routing and parsing path parameters, you can use the Benchmark tool (https://github.com/vapor/benchmarks) to generate specific benchmarks for comparison.

Feature sets

Performance is not the only factor we should consider. A production release of web application includes a complete set of robust features. Swift server-side frameworks often offer many useful functions that are common to most applications. Some common feature sets for Swift frameworks are listed as follows:

  • CLI tool: Offers tools for generating boilerplates, building, and deploying an application
  • Templating engine: Supports templating language for web content
  • Networking I/O: Facilitates the handling of requests over the network
  • Database ORM: Simplifies the querying for the back-end database
  • Logging framework: Helps catch useful information during runtime
  • Test framework: Creates unit tests for testing the web application
  • Authentication: Provides authentication features, such as user login or social login
  • Security framework: Adds encryption to communication and messaging pipelines, and sockets
  • Monitoring and diagnostics: Offers real-time monitoring and diagnostics
  • User session management: Manages a user's session after login
  • Cloud deployment: Helps deploy a server application in an automated way
  • Swift support: Updates to the latest Swift version quickly

When choosing the right server-side framework, we will need to check whether any of the features mentioned have already been integrated in the framework, or if integration of third-party libraries that implement such features are easy and straightforward.

Ecosystem

Ecosystem here can be interpreted as the choices of libraries or tools that a Swift server-side adopts and integrates into the framework. We may have preferences for some technologies, and at the same time, we may have reasons for avoiding other technologies as trade-offs in the design of our application. Sometimes, the effort will be daunting if we want to integrate a third-party library into the chosen framework that does not have the library included already. The best time-saving tip is to choose the framework that has the most preferred libraries so we can minimize the effort to do integration ourselves.

The main components and choices of third-party libraries in Vapor and Kitura are listed in the following table:

Feature Vapor Kitura
OS support macOS, Linux macOS, Linux
CLI Vapor Toolbox CLI, Vapor Console API Kitura CLI, Project Generator
Templating engine Leaf Stencil, Mustache, Markdown
Networking I/O SwiftNIO Kitura-NIO (use SwiftNIO and NIOOpenSSL), BlueSocket, Kitura-net
ORM Fluent: SQLite, MySQL, PostgreSQL, Redis Swift-Kuery-ORM, Swift-Kuery:, PostgreSQL, SQLite, Redis
Logging Logging API, PrintLogger, SwiftyBeaver Logging LoggerAPI, HeliumLogger
Route-type validation Vapor Validation n/a
Authentication Turnstile Kitura-Credentials: HTTP, Facebook, Google, GitHub
Security Vapor-Crypto / SwiftNIO SSL BlueSSLService
User session SessionMiddleware Kitura-Session
Monitoring & diagnostics n/a SwiftMetrics, Health
Container Docker Docker
Orchestration n/a Kubernetes / Helm
Cloud deployment Vapor Cloud IBM Cloud

In the rest of this book, we will visit most of the previously mentioned technologies again when we learn how to build web applications and services with Vapor and Kitura.

Community support

Developer community support is sometimes a deciding factor in the choice of a Swift server-side framework. Strong developer community support means that a framework's feature set is more complete, and there will be enough support when we encounter hurdles in working with the framework.

Vapor

Vapor enjoys healthy developer community support. Vapor users are well-known for their support and eagerness to help newcomers to Vapor community. There is a lot of activity in social channels. The Vapor community has recently moved their forums from Slack to Discord (http://discord.gg/BnXmVGA). There are also plenty of online learning resources, sample codes, tutorials, books, and community-contributed library plugins available to Vapor users. A word of caution, though: many of the tutorial and learning material for Vapor 2.0 or earlier, are outdated. Due to the substantial changes in Vapor 3.0, especially the migration to asynchronous non-blocking stacks based on SwiftNIO, many of the tutorials need to be revised and updated for Vapor 3.0.

Kitura

Kitura may have smaller community involvement currently, but IBM's engineers have been active and helpful on GitHub and online forums for new learners of server-side Swift. Kitura has a more complete cloud computing stack. It is easy for users to find the documentation and learning materials for not only the Swift server-side framework but also for other cloud technologies that are often used together with the Swift framework.

Perfect

Perfect stands out as having extensive tutorials, documentation, and training materials available on its website (https://perfect.org/tutorials.html) for Swift server-side developers. The Perfect framework is more mature, and its learning materials are well-organized. Currently, the Perfect user community has 69 repositories in the Perfect examples (https://github.com/PerfectExamples) repository on GitHub. New Perfect users can use the Slack (http://www.perfect.ly/) channels to interact with other developers and to get help from others.

You have been reading a chapter from
Hands-On Server-Side Web Development with Swift
Published in: Nov 2018
Publisher: Packt
ISBN-13: 9781789341171
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image