Vapor
Vapor (https://vapor.codes/ ) is the Swiss Army knife of the web frameworks in Swift. It is a framework to get developers building modern web apps, sites, APIs, and even real-time web apps, using web sockets. It is currently the most used package in Swift (https://packagecatalog.com/browse?chart=mostessential&page=1), more used than Kitura and Perfect, which are the other two popular server-side frameworks for Swift. Vapor has a strong and vibrant developer community where developers from different companies, including Apple, are contributing to the framework to make Vapor fast, stable, and extensible so that it is easy to use and build large-scale web apps with. Swift is the next big platform for web and backend development, and Vapor is the framework that will help Swift get there. Vapor is the future of web development on the server platform. Here are some reasons to get excited about Vapor:
- It has an amazing CLI tool that helps you create, build, run, and even deploy a Vapor app.
- It is very fast compared to other frameworks, such as Kitura or Perfect, based on independent benchmark tests. It is especially fast when compared to other languages, such as Ruby, PHP, or Node.js.
- It is secure from the beginning and has trusted encryption and TLS from OpenSSL and BCrypt hashing included by default to make security easy.
- It is very extensible as it is very easy to add middleware and even create extensions for both the framework and CLI tools to customize the developer experience. Vapor is also modular, so you can use parts of Vapor, such as the Vapor Engine, to build your HTTP Server. Vapor is more than just an HTTP Server with Routing, and you can substitute a Kitura HTTP Server in place of Vapor's default HTTP Server while using other parts of the framework, such as its powerful Object-relational mapping engine, database migrations, and the view rendering engine.
- It is heavily configurable via the config files that are in JSON format. The configurations allow for environment variable substitution, so you can easily swap out database URLs or other configurations for different environments using only environment variables.
- It uses the model-view-controller architectural pattern, popularized by Rails, making it easy to create and debug apps.
- It is resourceful by default, and has great APIs to build RESTful web applications. It is also resourceful in the sense that you can serve static assets such as CSS, JS, and even render views in different formats, such as HTML or JSON, depending on who is requesting a resource and with which format.
- It is expressive where you write less code to do more, making Vapor apps more concise and powerful.
- Vapor Apps are easy to deploy thanks to its cloud service, which is similar to Heroku, but you can also deploy the Vapor app to your cloud or data center if you like:
Considering that Vapor is more than just a simple HTTP server with routing like other server-side Swift frameworks and has all the bells and whistles of a full stack web application framework, it's an obvious choice that allows us to focus on writing the business logic for our application. We will be using Vapor to build our server-side component for the iOS apps that we'll be creating throughout this book.