Vapor — How to get started

Install, create and run a new Vapor project

Alexandre Cools
3 min readOct 20, 2020

What’s Vapor?

“Vapor is an open source web framework written in Swift. It can be used to create RESTful APIs, web apps, and real-time applications using WebSockets. In addition to the core framework, Vapor provides an ORM, a templating language, and packages to facilitate user authentication and authorization.” — from Wikipédia

Vapor installation

You can install Vapor on your machine with Homebrew. If you don’t have Homebrew installed on your machine, you can go to the official website to install it.

Once it’s done, open a terminal on your machine, then type the following command and validate it by pressing the return button:

brew install vapor

Tips: If you have the following error:

Vapor installation error

Simply follow the indications by entering the following command in your terminal window:

sudo chown —R $(whoami) /usr/local/share/man/man8

Once Vapor is installed on your machine, double check-it by doing this:

vapor --help

If Vapor is correctly installed, you should see the following result:

Vapor help command result

Now that Vapor is correctly installed on your machine, you should be able to create a new Vapor project.

New Vapor project creation

The command to create a new project is the following (don’t forget to replace [ProjectName] by your own project name):

vapor new [ProjectName] -n

“The -n flag gives you a bare bones template by automatically answering no to all questions.” — from Vapor docs

Vapor installation console logs

Congratulation, your project is now created and you’re ready to go!

Open the project with Xcode

To open your new project with Xcode, go to your project folder and double click on Package.swift. It will open Xcode and starting to download all required dependencies.

By default, Vapor come with a lot of dependencies:

Vapor dependencies

Once all dependencies are installed, you can build and run your Xcode project like any other Xcode project.

And then, you’ll see this message in your Xcode console:

Console log indicating vapor is running

So, if you go to localhost:8080 or 127.0.0.1:8080 in your favorite browser, you will see this result:

Vapor running web service

Ok, that’s not an incredible result, but your vapor project is now running and you can start to create something really amazing!

Note you can also see every requests in your Xcode console. It could be very useful to debug for example.

Tips: if you don’t want to open Xcode to be able to run your Vapor project, you can go to your Vapor project folder with your terminal, and then type:

vapor run

to start running your project. (To stop running your project without closing your terminal window, you can type Ctrl + C)

Vapor server running on a terminal window

🚀 What’s next?

See Vapor — Generated files overview if you want to learn more about Vapor.

And don’t forget to “clap” and share this article if you like it and want to see more content like this! 👏

If you have any question, feel free to let a comment right below, I’ll answer you with pleasure!

Thanks for reading,

--

--

Alexandre Cools

iOS Developer @LunabeeStudio 👨🏻‍💻 — Sport addict 🏊‍♂️🚴‍♂️🏃‍♂️ — Travel enthusiast ✈️