Server side Swift for Laravel developers part 1

Building a simple CRUD-app in Swift with Vapor 2

Jan Östlund
Aug 1, 2017 · 5 min read
Image for post
Image for post

tl;dr

Intro

Install Xcode, Homebrew Tap and Vapor

Create a new project

Image for post
Image for post
Image for post
Image for post

Install C MySQL library

Install and configure MySQL-drivers

Image for post
Image for post
Image for post
Image for post
{ "hostname": "127.0.0.1", "user": "root", "password": "", "database": "vapor" }
{ "driver": "mysql" }

Test your setup

import App 
import MySQLProvider
let config = try Config()
try config.addProvider(MySQLProvider.Provider.self)
try config.setup()
let drop = try Droplet(config)
try drop.setup()
drop.get("version") {
request in let db = try drop.mysql()
let version = try
db.raw("SELECT version()") return JSON(node: version)
}
try drop.run()
Image for post
Image for post
Image for post
Image for post

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store