SlideShare a Scribd company logo
jensravens.com / AppBuilders 2017
Server Side Swift
Why it’s awesome and
why you should care.
Jens Ravens
jensravens.com / AppBuilders 2017
😱
jensravens.com / AppBuilders 2017
😱
jensravens.com / AppBuilders 2017
😱
jensravens.com / AppBuilders 2017
Who is this guy?
jensravens.com / AppBuilders 2017
Who is this guy?
(aka the shameless self promotion part)
jensravens.com / AppBuilders 2017
Jens Ravens
Developer at nerdgeschoss, a mobile first dev agency for sophisticated software. We
help startups and medium businesses to build awesome stuff.
jensravens.com / AppBuilders 2017
Jens Ravens
50% iOS / macOS using Swift
50% Web / API using Ruby on Rails
jensravens.com / AppBuilders 2017
Jens Ravens
Also I blog about Swift stuff on jensravens.com and organize
the monthly swift.berlin meetup.
jensravens.com / AppBuilders 2017
What I am going to talk about…
a short introduction to http, the internet and everything else
abstracting the server implementation from request handling
Model, View, Controller, Router, Storage
why Swift on the server might actually be a good idea
the current state of server side Swift
jensravens.com / AppBuilders 2017
Why Swift on the server might actually
be a good idea.
🚀 🤓
speed developer happiness
jensravens.com / AppBuilders 2017
Raw Performance. 🚀
Ryan Collins, August 2016
jensravens.com / AppBuilders 2017
So server side Swift is screaming fast.
It gives you more bang for the buck.
But here is a well kept secret…
I just don't care.
jensravens.com / AppBuilders 2017
A look at last month’s spendings.
Server Costs
2 %
Office
11 %
Salaries
87 %
jensravens.com / AppBuilders 2017
A look at last month’s spendings.
faster development = more revenue
jensravens.com / AppBuilders 2017
Swift is fast enough. We should focus on
developer productivity instead.
jensravens.com / AppBuilders 2017
A short introduction to http, the internet and
everything else.
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 7897
Connection: Keep-Alive
<!DOCTYPE html>
<html lang="en">
Browser
http://jensravens.com
DNS Server
;; ANSWER SECTION:
jensravens.com. 3600 INA 37.120.178.83
37.120.178.83
Server
Load Balancer
App App
GET / HTTP/1.1
Host: jensravens.com
User-Agent: curl/7.43.0
Accept: */*
jensravens.com / AppBuilders 2017
Hey, that’s just some plain text over tcp!
Yep, you’re right.
jensravens.com / AppBuilders 2017
Get a Request, give a Response.
public protocol Response {
var headers: [String: HeaderType] { get }
var code: StatusCode { get }
var content: Streamable { get }
}
public protocol Request {
var method: HTTPMethod { get }
var path: String { get }
var params: [String:String] { get }
var headers: [String:String] { get }
var format: Format { get }
var body: Streamable? { get }
}
public protocol Streamable {
var stream: Void -> NSData? { get }
}
jensravens.com / AppBuilders 2017
But isn’t this the same for every app on every server?
Yep, you’re right.
jensravens.com / AppBuilders 2017
Abstracting the server implementation
from request handling
Ruby: Rack.
Every app is just a function transforming request to response.
jensravens.com / AppBuilders 2017
Abstracting the server implementation
from request handling
Meet the Open Swift Standards.
https://github.com/open-swift
Open Swift Standard
Server Implementation
Your awesome App
The Internetz
and the Swift Server APIs.
https://swift.org/server-apis
jensravens.com / AppBuilders 2017
Structuring Web Applications in Swift with MVC-RS
*
*Term shamelessly copied from a presentation
by Greg Lhotellier at SwiftConf 2016
jensravens.com / AppBuilders 2017
public typealias Controller = Request throws -> Response
let myApp: Controller = { request in
return Response(code: 200, headers: [:], content: "Hello World")
}
Get a Request, give a Response: the Controller.
jensravens.com / AppBuilders 2017
Making things pretty: Rendering Views.
public protocol View {
func render() throws -> Streamable
func render() throws -> Response
var contentType: Format { get }
}
jensravens.com / AppBuilders 2017
public struct JSONView: View {
public var contentType: Format { return .JSON }
let contents: AnyObject
public init(_ contents: AnyObject) {
self.contents = contents
}
public func render() throws -> Streamable {
return try NSJSONSerialization.dataWithJSONObject(
contents, options: .PrettyPrinted)
}
}
jensravens.com / AppBuilders 2017
Models and Persistence: Storage.
protocol Repository {
associatedtype Element
func find(index: Int) -> Element
func query(conditions: Predicate) -> [Element]
}
struct Post {
let id: Int
var title: String
var content: String
}
let post = try postsRepository.find(request.params[“id"])
let attributes = ["id": post.id, "title": post.title]
return JSONView(attributes)
jensravens.com / AppBuilders 2017
let myApp: Controller = { request in
json = JSONView(["message":"Hello World #{request.params["id"]}"])
return Response(code: 200, headers: [:], content: try json.render())
}
Where to go next: the Router.
public final class Router {
public func get(path: String, app: Void -> Controller)
public func post(path: String, app: Void -> Controller)
…
public func controller(request: Request) throws -> Response
}
let router = Router()
router.get("messages/:id") { myApp }
serve(router.controller)
jensravens.com / AppBuilders 2017
MVC-RS in Review
Database External Webservice
Repository RepositoryRepository
Controller Controller
Model View Model View
Router
jensravens.com / AppBuilders 2017
Some Observations.
Models don’t inherit or conform to anything.
Controllers can call other controllers (Middleware).
Client and server architecture are pretty similar which allows code sharing.
Routers are also controllers and therefore can be nested.
jensravens.com / AppBuilders 2017
The current state of server side Swift.
jensravens.com / AppBuilders 2017
The current state of server side Swift.
https://vapor.codes
jensravens.com / AppBuilders 2017
The current state of server side Swift.
http://www.kitura.io
jensravens.com / AppBuilders 2017
My personal wishlist.
be explicit - but don’t be verbose
more projects conforming to Open Swift Standards Server APIs
don’t just imitate other frameworks - use Swift’s
modern and type safe features
a framework that comes totally configurable, but batteries included
jensravens.com / AppBuilders 2017
🤓
happy developer
jensravens.com / AppBuilders 2017
Thank you.
Jens Ravens / @jensravens

More Related Content

PDF
Server Side Swift
KEY
Plack at YAPC::NA 2010
PDF
Building an API with Django and Django REST Framework
KEY
Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010
KEY
Intro to PSGI and Plack
KEY
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
PPS
Web Development in Perl
PDF
Plack basics for Perl websites - YAPC::EU 2011
Server Side Swift
Plack at YAPC::NA 2010
Building an API with Django and Django REST Framework
Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010
Intro to PSGI and Plack
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
Web Development in Perl
Plack basics for Perl websites - YAPC::EU 2011

What's hot (20)

PPT
appache_1
PPTX
PSGI and Plack from first principles
PDF
WP Weekend #2 - Corcel, aneb WordPress přes Laravel
PDF
Lies, Damn Lies, and Benchmarks
KEY
Plack at OSCON 2010
PDF
Selenium sandwich-3: Being where you aren't.
PPTX
Ruby On Grape
PDF
CPANTS: Kwalitative website and its tools
PDF
Build REST API clients for AngularJS
PDF
A reviravolta do desenvolvimento web
ODP
Modern Perl
PDF
Serverless Ballerina
PDF
Release with confidence
PPTX
No callbacks, No Threads - Cooperative web servers in Ruby 1.9
PDF
Deploying a Location-Aware Ember Application
PDF
Introduction to the New Asynchronous API in the .NET Driver
PDF
SDPHP - Percona Toolkit (It's Basically Magic)
PPTX
Node.js - Advanced Basics
PDF
The journey of asyncio adoption in instagram
PDF
AWS SDK for PHP のインストールから 始めるクラウドマスターへの道 〜 Promise による非同期オペレーション 〜
appache_1
PSGI and Plack from first principles
WP Weekend #2 - Corcel, aneb WordPress přes Laravel
Lies, Damn Lies, and Benchmarks
Plack at OSCON 2010
Selenium sandwich-3: Being where you aren't.
Ruby On Grape
CPANTS: Kwalitative website and its tools
Build REST API clients for AngularJS
A reviravolta do desenvolvimento web
Modern Perl
Serverless Ballerina
Release with confidence
No callbacks, No Threads - Cooperative web servers in Ruby 1.9
Deploying a Location-Aware Ember Application
Introduction to the New Asynchronous API in the .NET Driver
SDPHP - Percona Toolkit (It's Basically Magic)
Node.js - Advanced Basics
The journey of asyncio adoption in instagram
AWS SDK for PHP のインストールから 始めるクラウドマスターへの道 〜 Promise による非同期オペレーション 〜
Ad

Similar to Server Side Swift - AppBuilders 2017 (20)

PPTX
AFNetworking
PDF
Server Side Swift with Swag
PDF
The state of server-side Swift
KEY
Rails as iOS Application Backend
PPT
Openstack swift - VietOpenStack 6thmeeetup
PDF
Object Storage with Swift Cloud storage administration through OpenStack 1. A...
PDF
Designing and Debugging Mobile Apps with an Embedded, Scriptable Web Server
PDF
Swift Summit 2017: Server Swift State of the Union
PDF
Building micro-web-server
PDF
Server Side? Swift
PDF
iOS Swift application architecture
PPT
Exploring Openstack Swift(Object Storage) and Swiftstack
PDF
APIs for modern web apps
PDF
Swift Install Workshop - OpenStack Conference Spring 2012
PPTX
Swift at IBM: Mobile, open source and the drive to the cloud
KEY
20120802 timisoara
PDF
Initial presentation of swift (for montreal user group)
KEY
Speedupiosdevelopment
ZIP
iPhone and Rails integration
KEY
20120306 dublin js
AFNetworking
Server Side Swift with Swag
The state of server-side Swift
Rails as iOS Application Backend
Openstack swift - VietOpenStack 6thmeeetup
Object Storage with Swift Cloud storage administration through OpenStack 1. A...
Designing and Debugging Mobile Apps with an Embedded, Scriptable Web Server
Swift Summit 2017: Server Swift State of the Union
Building micro-web-server
Server Side? Swift
iOS Swift application architecture
Exploring Openstack Swift(Object Storage) and Swiftstack
APIs for modern web apps
Swift Install Workshop - OpenStack Conference Spring 2012
Swift at IBM: Mobile, open source and the drive to the cloud
20120802 timisoara
Initial presentation of swift (for montreal user group)
Speedupiosdevelopment
iPhone and Rails integration
20120306 dublin js
Ad

More from Jens Ravens (8)

PDF
Turning it up to 11 - Scaling Ruby on Rails to 100k rps
PDF
Working with Xcode and Swift Package Manager
PDF
Taming Asynchronous Transforms with Interstellar
PDF
Hipster oriented programming (Mobilization Lodz 2015)
PDF
Hipster Oriented Programming
PDF
Swift 2
PDF
Functional Reactive Programming without Black Magic (UIKonf 2015)
PDF
Swift: Immutability and You
Turning it up to 11 - Scaling Ruby on Rails to 100k rps
Working with Xcode and Swift Package Manager
Taming Asynchronous Transforms with Interstellar
Hipster oriented programming (Mobilization Lodz 2015)
Hipster Oriented Programming
Swift 2
Functional Reactive Programming without Black Magic (UIKonf 2015)
Swift: Immutability and You

Recently uploaded (20)

PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
System and Network Administration Chapter 2
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
L1 - Introduction to python Backend.pptx
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Introduction to Artificial Intelligence
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
System and Network Administraation Chapter 3
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
AI in Product Development-omnex systems
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
System and Network Administration Chapter 2
Odoo Companies in India – Driving Business Transformation.pdf
L1 - Introduction to python Backend.pptx
How Creative Agencies Leverage Project Management Software.pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Introduction to Artificial Intelligence
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Wondershare Filmora 15 Crack With Activation Key [2025
System and Network Administraation Chapter 3
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Odoo POS Development Services by CandidRoot Solutions
How to Choose the Right IT Partner for Your Business in Malaysia
Navsoft: AI-Powered Business Solutions & Custom Software Development
AI in Product Development-omnex systems
PTS Company Brochure 2025 (1).pdf.......
2025 Textile ERP Trends: SAP, Odoo & Oracle
VVF-Customer-Presentation2025-Ver1.9.pptx
Operating system designcfffgfgggggggvggggggggg
Upgrade and Innovation Strategies for SAP ERP Customers

Server Side Swift - AppBuilders 2017

  • 1. jensravens.com / AppBuilders 2017 Server Side Swift Why it’s awesome and why you should care. Jens Ravens
  • 5. jensravens.com / AppBuilders 2017 Who is this guy?
  • 6. jensravens.com / AppBuilders 2017 Who is this guy? (aka the shameless self promotion part)
  • 7. jensravens.com / AppBuilders 2017 Jens Ravens Developer at nerdgeschoss, a mobile first dev agency for sophisticated software. We help startups and medium businesses to build awesome stuff.
  • 8. jensravens.com / AppBuilders 2017 Jens Ravens 50% iOS / macOS using Swift 50% Web / API using Ruby on Rails
  • 9. jensravens.com / AppBuilders 2017 Jens Ravens Also I blog about Swift stuff on jensravens.com and organize the monthly swift.berlin meetup.
  • 10. jensravens.com / AppBuilders 2017 What I am going to talk about… a short introduction to http, the internet and everything else abstracting the server implementation from request handling Model, View, Controller, Router, Storage why Swift on the server might actually be a good idea the current state of server side Swift
  • 11. jensravens.com / AppBuilders 2017 Why Swift on the server might actually be a good idea. 🚀 🤓 speed developer happiness
  • 12. jensravens.com / AppBuilders 2017 Raw Performance. 🚀 Ryan Collins, August 2016
  • 13. jensravens.com / AppBuilders 2017 So server side Swift is screaming fast. It gives you more bang for the buck. But here is a well kept secret… I just don't care.
  • 14. jensravens.com / AppBuilders 2017 A look at last month’s spendings. Server Costs 2 % Office 11 % Salaries 87 %
  • 15. jensravens.com / AppBuilders 2017 A look at last month’s spendings. faster development = more revenue
  • 16. jensravens.com / AppBuilders 2017 Swift is fast enough. We should focus on developer productivity instead.
  • 17. jensravens.com / AppBuilders 2017 A short introduction to http, the internet and everything else.
  • 18. HTTP/1.1 200 OK Content-Type: text/html Content-Length: 7897 Connection: Keep-Alive <!DOCTYPE html> <html lang="en"> Browser http://jensravens.com DNS Server ;; ANSWER SECTION: jensravens.com. 3600 INA 37.120.178.83 37.120.178.83 Server Load Balancer App App GET / HTTP/1.1 Host: jensravens.com User-Agent: curl/7.43.0 Accept: */*
  • 19. jensravens.com / AppBuilders 2017 Hey, that’s just some plain text over tcp! Yep, you’re right.
  • 20. jensravens.com / AppBuilders 2017 Get a Request, give a Response. public protocol Response { var headers: [String: HeaderType] { get } var code: StatusCode { get } var content: Streamable { get } } public protocol Request { var method: HTTPMethod { get } var path: String { get } var params: [String:String] { get } var headers: [String:String] { get } var format: Format { get } var body: Streamable? { get } } public protocol Streamable { var stream: Void -> NSData? { get } }
  • 21. jensravens.com / AppBuilders 2017 But isn’t this the same for every app on every server? Yep, you’re right.
  • 22. jensravens.com / AppBuilders 2017 Abstracting the server implementation from request handling Ruby: Rack. Every app is just a function transforming request to response.
  • 23. jensravens.com / AppBuilders 2017 Abstracting the server implementation from request handling Meet the Open Swift Standards. https://github.com/open-swift Open Swift Standard Server Implementation Your awesome App The Internetz and the Swift Server APIs. https://swift.org/server-apis
  • 24. jensravens.com / AppBuilders 2017 Structuring Web Applications in Swift with MVC-RS * *Term shamelessly copied from a presentation by Greg Lhotellier at SwiftConf 2016
  • 25. jensravens.com / AppBuilders 2017 public typealias Controller = Request throws -> Response let myApp: Controller = { request in return Response(code: 200, headers: [:], content: "Hello World") } Get a Request, give a Response: the Controller.
  • 26. jensravens.com / AppBuilders 2017 Making things pretty: Rendering Views. public protocol View { func render() throws -> Streamable func render() throws -> Response var contentType: Format { get } }
  • 27. jensravens.com / AppBuilders 2017 public struct JSONView: View { public var contentType: Format { return .JSON } let contents: AnyObject public init(_ contents: AnyObject) { self.contents = contents } public func render() throws -> Streamable { return try NSJSONSerialization.dataWithJSONObject( contents, options: .PrettyPrinted) } }
  • 28. jensravens.com / AppBuilders 2017 Models and Persistence: Storage. protocol Repository { associatedtype Element func find(index: Int) -> Element func query(conditions: Predicate) -> [Element] } struct Post { let id: Int var title: String var content: String } let post = try postsRepository.find(request.params[“id"]) let attributes = ["id": post.id, "title": post.title] return JSONView(attributes)
  • 29. jensravens.com / AppBuilders 2017 let myApp: Controller = { request in json = JSONView(["message":"Hello World #{request.params["id"]}"]) return Response(code: 200, headers: [:], content: try json.render()) } Where to go next: the Router. public final class Router { public func get(path: String, app: Void -> Controller) public func post(path: String, app: Void -> Controller) … public func controller(request: Request) throws -> Response } let router = Router() router.get("messages/:id") { myApp } serve(router.controller)
  • 30. jensravens.com / AppBuilders 2017 MVC-RS in Review Database External Webservice Repository RepositoryRepository Controller Controller Model View Model View Router
  • 31. jensravens.com / AppBuilders 2017 Some Observations. Models don’t inherit or conform to anything. Controllers can call other controllers (Middleware). Client and server architecture are pretty similar which allows code sharing. Routers are also controllers and therefore can be nested.
  • 32. jensravens.com / AppBuilders 2017 The current state of server side Swift.
  • 33. jensravens.com / AppBuilders 2017 The current state of server side Swift. https://vapor.codes
  • 34. jensravens.com / AppBuilders 2017 The current state of server side Swift. http://www.kitura.io
  • 35. jensravens.com / AppBuilders 2017 My personal wishlist. be explicit - but don’t be verbose more projects conforming to Open Swift Standards Server APIs don’t just imitate other frameworks - use Swift’s modern and type safe features a framework that comes totally configurable, but batteries included
  • 36. jensravens.com / AppBuilders 2017 🤓 happy developer
  • 37. jensravens.com / AppBuilders 2017 Thank you. Jens Ravens / @jensravens