iPS 209: Vapor with Bob Snyder

On today's episode of iPhreaks, Andrew Madsen and Jaim Zuber talk about Vapor with Bob Snyder. Bob is on the show today to discuss the structure of Vapor and web app deployment, etc. Don't miss this one!

[00:01:20] – Introduction on Vapor

Vapor is a server-side Swift framework. It came out two months after Swift became open-source. A couple of weeks ago, they just released Vapor 2.0. It’s a big jump from 1.5. Swift has protocols and has incredible performance as compared to Objective-C and other languages like JavaScript. It deserves more attention.

[00:02:30] – Back-end development before Vapor

Bob is a former graphic designer. He went to a boot camp last year and made that career shift. The boot camp focused on Python and iOS but that was all front-end for apps.

Right now, he is a full-stack developer for a start-up called Crew and he works on Objective-C and Python, and Python Django for the backend. You can deploy, build, and have a production-ready server-side Swift application but you probably want to keep it for a small to mid-size projects. It’s not quite enterprise-level yet.

[00:03:35] – Swift vs. Python

Besides the curly brackets, Bob also loves the Swift protocols. With these protocols, you can apply pretty much different attributes to a class. Working with Xcode and protocols, it gives you good practices for building applications. It’s also type-safe. When it comes to making variables, knowing that you’re keeping the same type of values is very important. That’s actually one of the reasons why the performance is better than JavaScript that isn’t type-safe.

[00:04:45] – Projects with Vapor

Bob has a project with his friend, and they’re making it open-source. It’s a web-based application where you just insult your friends and maybe insult you back. It goes back and forth. In doing that, what allowed Bob to really explore is how easy it is to set up relationships for your database inside Swift versus something else like Python.

[00:05:40] – Structure of Vapor

You have the Droplet which is your entire application. It’s where everything comes down to. That is your server. Everything else just kind of relates to that. You have the Vapor Nodes, which is going to be your central point for all of your data types. The real premise of the server is you have information that you take from outside, get request, you process them, and most of the time that you’re sending it to the database or returning it without going to the database. Each one of those parts to this environment generally takes a lot of interaction to get information for one piece to the next. That’s what vapor nodes kind of comes into play. It makes using that data very easy.

[00:06:30] – Node

A node is a class that has protocols built on top of it. If you want to return a JSON object with a request that you got, you can immediately spit out a JSON object. You get some information from the database. It’s basically a converter that you can return almost any format that you will need inside of Vapor.

[00:08:25] – Fluent

Nodes interact with Fluent. It allows Vapor to communicate with whatever database you’re using. It makes it easy to go from Vapor to a MySQL, a Postgre, or a MongoDB database. You can have a basic server. You’re going to have the Droplet. You’re going to have the information you want to get into a Node. And then, you’re going to send that information to Fluent. Then, Fluent will communicate your profile of the database. That will send on to the actual database. If you want to change the database you’re using, you can do that without changing Fluent, without changing Nodes, or the Droplet. All you have to do is change how your profile on the back-end.

[00:09:30] – Droplets

Vapor has different packages that are built into the Vapor library. The Droplet is the thing that you create. You instantiate one of those. That’s the web server and you can attach handlers for URL’s for routing to it, etc. It’s a top level application where everything else goes through.

Actually, between 1.5 and 2, they’ve made some improvements to the structure of it, as well. In 1.5, they have a lot of things in their main .swift file. And now, it’s really down to 6 lines of code. They have everything partitioned out.

[00: 11:05] – Vapor is modular

That is one reason why Bob thinks Vapor is going to outlast a lot of the other frameworks. You don’t really have to use every part of it. It also allows you to add-in whichever tool you need. Everything’s modular.

[00: 12:50] – Who’s behind Vapor?

They’re called Node. They’re based out of London. They’ve been financing the Vapor project early on. But it was Tanner Nelson and Logan Wright who founded it. They’re still both heading it.

[00: 14:25] – Tools to create new Vapor project

It’s really simple if you can break into a terminal. You will have to download Vapor. You have one command for Vapor. It constructs a framework for you. Vapor xcode will create your Xcode build file. If you check on the run schema to your Mac, you can just run it as a server straight to Xcode.

[00: 18:25] – Validation, Authentication

They have this validation tool that fully manages Swift’s protocols. The authentication is also there. It helps you to connect securely with your users. It’s not in their 2.0 docs but the 1.5 web sockets are still compatible with Vapor 2.0.

[00: 21:30] – Web app deployment

Vapor does have support for Heroku. That’s one of the first deployment options that they have. But using Ubuntu server is going to be the better option down that road. Heroku is good but it’s not something you have that much control when it comes to scaling. If you ever need to deploy something larger, to a cloud-based ecosystem, try to figure out Ubuntu, try to figure out better ways to deploy it. Heroku used to be the only deployment option that they offer but now they have Nginx and Supervisor.

There’s a build pack for Heroku that is on Github. Just point the Heroku command line tool to the build pack on Github and it figures out what needs to be done. Digital Ocean also has an option that’s using Docker. Docker container probably uses any number of cloud hosting – Amazon, Azure.

[00: 25:35] – Swift 4

They’re expecting that this is going to be the first real stable build of Swift. If 4.0 is a stable build as people are expecting, that could be a really big deal for Vapor. You can see enterprise-level applications. They’re talking about implementing that next year. It could lead to a full-stack Swift environment. We can see an environment where you have a full-stack that has no HTML, no CSS, and no JavaScript. It’s just all Swift and possibly XML.


Bob Snyder

Andrew Madsen

Jaim Zuber

  • Blog post: Overview of Swift Serve-side Frameworks