Vapor is a web framework written in Swift. It was mention in the Platforms State of the Union address during WWDC and it got me curious, what is Vapor, and why nobody is using it?

Background

I have been a web developer for decades running plain php in WordPress way back in the late 90s. As the tech evolves, so do my tools. Going from PHP in WordPress to Ruby on Rails to JavaScript back to PHP on Laravel, and now exploring Vapor on Swift.

What’s Similar (and a crash course to web frameworks)


This is what a typical web framework looks like. There are variations to this workflow, but web frameworks usually build like this.

For all intent and purpose, Vapor is a web framework. Things started out as webservers serving mostly static content. Later, people figured out that it would be useful if the end users could send back content like shopping lists or payment tokens. And work is done to make it more useful and capable.

And now, we pretty landed on the MVC pattern. Well, code to handle traffic from the web is divided into three different types: Model, View, and Controller.

When a request comes through the web and hits the server, it will go through the Router. The Router is the Harry Porter Magic Routing Hat which will determine where the traffic will go. If the request is valid, it will go to the appropriate Controller which will be explained later.

Model is how we describe the data, they are backed by datastore which in most cases is a relational database like SQLite or MySQL. Recently, the datastore has changed to NoSQL, blocks in a storage drive or just scribbles on a file. Things change to meet different gotchas but the concept is the model presents the data in the framework

View is what users would normally see when they visit a homepage. When you visit a website like Tech Journeyman, what the framework or server presents itself is called the View. Over the years, web frameworks have evolved from displaying just HTML to binary data, JSON (stripped-down text representation of data), or even files like PDF, pictures, videos, and music.

Controller is the glue between View and Model. After a request has been vetted by the Router, it will go to the Controller where the request will translate into commands. Controller is where a request becomes the business logic, Models are manipulated and finally, View is presented. Business logic might be stashed away in a library somewhere in the codebase, but Controller is where it is invoked.

On top of the MVC layer, there are the Middleware libraries where one would inject as the request goes from one part to another. Middleware libraries are usually authentication, connection with 3rd party services like AWS S3 storage, and many more. Middleware is not the end-all, it’s the tool to get a job done.

Best practices include Unit Testing where every piece of the code is tested to ensure that the code is doing what is supposed to be doing and can handle errors like a blank request and much more.

Vapor has all the above features and much more like websockets which will not be covered here. However, these are the normal use cases where one would build a software-as-a-service platform and Vapor seems to cover it well.

What’s special

So, what makes Vapor special than the garden variety of web frameworks? For starters, it is built on Swift language, the official language of Apple Inc. Swift is a compiled language, unlike the popular ones like JavaScript, PHP, and Ruby which are interpreted on the fly. The benefit of a compiled language such as Swift is performance.

That being said, performance is not the end-all for web frameworks because, to be frank, performance is not a major issue for 99.9% of websites out on the internet.

The most important feature of Vapor is that if you are working in a Swift environment, you have a web framework in your toolbox that can do what is needed to be done.

Reference

Plug

Support this free website by visiting my Amazon affiliate links. Any purchase you make will give me a cut without any extra cost to you

BasePro
iPhonesiPhone 16 / iPhone 16 Plus - (Amazon)iPhone 16 Pro / iPhone 16 Pro Max - (Amazon)
WatchApple Watch SE (Amazon) / Apple Watch Series 10Apple Watch Ultra 2 (Amazon)
AirPodsAirPods 4 (Amazon)AirPods Pro 2 (Amazon) / AirPods Max (Amazon)
iPadiPad 10 (Amazon) / iPad Mini (Amazon)iPad Air M2 (Amazon) / iPad Pro M4 (Amazon)
LaptopsMacBook Air M3 (Amazon)MacBook Pro M3 (Amazon) / MacBook Pro M3 Pro/Max (Amazon)
DesktopMac Mini (Amazon) / iMac (Amazon)Mac Studio / Mac Pro
DisplaysStudio Display (Amazon)Pro Display XDR (Amazon)

Other Ecosystem Items