Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ServerSideSwift Berlin

Ian Partridge
September 14, 2018

ServerSideSwift Berlin

Ian Partridge

September 14, 2018
Tweet

More Decks by Ian Partridge

Other Decks in Programming

Transcript

  1. > 4x Increase in downloads last 12 Months 1,000s Instances

    on IBM Cloud Parity With Ruby on IBM Cloud Digital Bank Agrochemical Company
  2. var express = require('express') var app = express() // respond

    with "hello world" when a GET request is made app.get('/', function (req, res) { res.send('hello world’) })
  3. { "name": "", "photo": "", "dateOfBirth": { "year": "month": "day":

    } } struct Profile { var name: String var photo: Data var dateOfBirth: Date } Swift var profile: [String : Any] Swift KITURA
  4. guard let name = json["name"].string else { response.status(.unprocessableEntity) response.send(json: JSON([

    "error": "Type mismatch, `name` expected to be a String" ])) next() } guard json["photo"].exists() else { response.status(.unprocessableEntity) response.send(json: JSON([ "error": "Missing required property photo`" ])) next() } guard let photoString = json["photo"].string else { response.status(.unprocessableEntity) response.send(json: JSON([ "error": "Type mismatch, `photo` expected to be a String" ])) next() } guard let photo = Data(base64Encoded: photoString) else { response.status(.unprocessableEntity) response.send(json: JSON([ "error": "Type mismatch, `photo` expected to be Base64 encoded data" ])) next() }
  5. struct Profile: Codable { var name: String var photo: Data

    var dateOfBirth: Date } router.post("/profile", handler: postProfile) func postProfile(request: RouterRequest, response: RouterResponse, next: () -> Void) { let profile = try request.read(as: Profile.Type) }
  6. struct Profile: Codable { var name: String var photo: Data

    var dateOfBirth: Date } router.post("/profile", handler: postProfile) func postProfile(profile: Profile, respondWith: @escaping (Profile?, Error?) -> Void) { respondWith(profile, nil) }
  7. Codable Routing Codable Query Parameters Type Safe Middlewares Type Safe

    Auth KituraKit Prometheus Monitoring Type Safe Templating Codable URL Encoded Forms Kitura app SwiftKueryORM OpenAPI Support Type Safe Sessions Kitura CLI
  8. KITURA Kitura 2.5 August 31, 2018 • SwiftNIO Support •

    Pluggable Encoders • OpenAPI Query Parameters • Performance KITURA Kitura 2.0 August 31, 2017 • Codable Routing APIs • Swift 4.0 Support • Performance KITURA Kitura 2.4 June 1, 2018 • Type Safe Middleware • Automatic OpenAPI Support • Type Safe Templating • Swift 4.2 Support KITURA Kitura 2.3 April 17, 2018 • Type Safe URLEncoded Forms • Codable RequestErrors • Performance and Memory • Swift 4.1 Support KITURA Kitura 2.2 January 30, 2018 • Type Safe Query Parameters • API Doc Improvements • Swift 4.0.3 Support KITURA Kitura 2.1 December 18, 2017 • Additional Codable Routing APIs • Array mapping in Query Parameters • Support for Range Requests • Swift 4.0.2 Support
  9. • Description format for REST APIs • Declaratively document your

    entire API • Endpoints and operations • Input and output parameters • Status codes and content types • Authentication • Swagger Editor • Swagger UI • Swagger Codegen
  10. SwiftNIO • Async I/O framework for Swift • Port of

    Netty • Supported in Kitura 2.5 • HTTP • WebSocket • Feedback needed!