Building servers using Vapor's engine
Before we start using Vapor, let's see how the Vapor package is built on top of its engine package. This will give us a better understanding of what, exactly, Vapor provides, and what is provided by the dependencies that it consumes, in case you need to build a lightweight server or want to embrace building your own variation of a web framework. We will do the following:
- First, build a basic web server that returns Hello World
- Then, modify our Hello World server to serve file content, making a static file server similar to Apache or Nginx
- Lastly, we will build a web socket server that will accept connections and echo back the message sent via the web socket connection
Going through the exercise of building these different kinds of servers using Vapor's engine will help us understand how Vapor works under the hood. It will also help us realize that building a large scale web application requires a lot of features, such as routing, persisting to the database, migrations, rendering HTML templates, and much more, which Vapor provides via its other Swift packages. This makes Vapor very modular, and anyone who wants to build something lightweight can pick and choose the modules they want, or they can use the Vapor Swift package to get the entire bundle pre-configured, making it easy to build large-scale web applications quickly.