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

IBM & Server Side Swift - Making Your Mobile Developers Full Stack

David Okun
November 08, 2017

IBM & Server Side Swift - Making Your Mobile Developers Full Stack

A talk about Kitura 2.0, and the benefits of running Swift on the Server with IBM

David Okun

November 08, 2017
Tweet

More Decks by David Okun

Other Decks in Programming

Transcript

  1. A Brief History of Swift • June 2014 - Swift

    is released • June 2015 - Swift on Linux is announced @dokun24
  2. A Brief History of Swift • June 2014 - Swift

    is released • June 2015 - Swift on Linux is announced • December 2015 - swift.org goes live @dokun24
  3. A Brief History of Swift • June 2014 - Swift

    is released • June 2015 - Swift on Linux is announced • December 2015 - swift.org goes live • March 2016 - First Linux build available @dokun24
  4. A Brief History of Swift • June 2014 - Swift

    is released • June 2015 - Swift on Linux is announced • December 2015 - swift.org goes live • March 2016 - First Linux build available • June 2016 - Kitura at WWDC @dokun24
  5. A Brief History of Swift • June 2014 - Swift

    is released • June 2015 - Swift on Linux is announced • December 2015 - swift.org goes live • March 2016 - First Linux build available • June 2016 - Kitura at WWDC • October 2017 - Kitura 2.0 @dokun24
  6. Kitura - HTTP for Swift • Architected like Express.js •

    Written with Swift on Linux • Front-end templating @dokun24
  7. Kitura - HTTP for Swift • Architected like Express.js •

    Written with Swift on Linux • Front-end templating • Persistence layer compatibility @dokun24
  8. Kitura 2.0 • KituraKit - for clients • A shiny

    new CLI • Codable routing @dokun24
  9. Kitura 1.x Parsing router.post("/animals") { request, response, next in defer

    { next() } guard let animalJSON = request["animal"] as? [String: AnyObject] else { response.send(json: JSON(["Error" : "Could not parse object"])) } let animal = Animal(json: animalJSON) if animal.save() { response.status(.ok).send(json: JSON(animalJSON)) } else { response.status(.badRequest) } } @dokun24
  10. Kitura 1.x Parsing init? (json: [String: AnyObject]) { if let

    animalID = json[AnimalJSONConstants.id] as? Int, let photoURL = json[AnimalJSONConstants.photoURL] as? String, let looksFriendly = json[AnimalJSONConstants.looksFriendly] as? Bool, let plural = json[AnimalJSONConstants.plural] as? Bool, let typeString = json[AnimalJSONConstants.type] as? String { self.animalID = animalID self.photoURL = photoURL self.looksFriendly = looksFriendly self.plural = plural self.type = typeString == AnimalConstants.bear ? AnimalType.Bear : AnimalType.Cat } else { return nil } } @dokun24
  11. Kitura 2.x Parsing @dokun24 router.post(“/animals”, handler: store) func store(animal: Animal,

    completion: (Animal?, RequestError?) -> Void) -> Void { if animal.save() { completion(animal, nil) } else { completion(nil, RequestError(httpCode: .400)) } }
  12. Codable Protocol • Responsible for encoding and decoding objects to

    another type, such as JSON • Sub-protocols: Encodable and Decodable @dokun24
  13. Codable Protocol • Responsible for encoding and decoding objects to

    another type, such as JSON • Sub-protocols: Encodable and Decodable • Forces an object to be ready-made for HTTP @dokun24
  14. Kitura CLI • Uses Yeoman to generate projects • Ready

    made for IBM Cloud deployment @dokun24
  15. Kitura CLI • Uses Yeoman to generate projects • Ready

    made for IBM Cloud deployment • Analytics, health, OpenAPI UI @dokun24
  16. Kitura CLI -rw-r--r-- 1 davidokunibm staff 992B Nov 6 13:26

    Dockerfile -rw-r--r-- 1 davidokunibm staff 876B Nov 6 13:26 Dockerfile-tools drwxr-xr-x 37 davidokunibm staff 1.2K Nov 6 13:47 Application.xcodeproj -rw-r--r-- 1 davidokunibm staff 1.1K Nov 6 13:26 LICENSE -rw-r--r-- 1 davidokunibm staff 5.4K Nov 6 13:26 Package.resolved -rw-r--r-- 1 davidokunibm staff 1.1K Nov 6 13:26 Package.swift -rw-r--r-- 1 davidokunibm staff 6.7K Nov 6 13:26 README.md drwxr-xr-x 4 davidokunibm staff 136B Nov 6 13:26 Sources drwxr-xr-x 4 davidokunibm staff 136B Nov 6 13:26 Tests drwxr-xr-x 3 davidokunibm staff 102B Nov 6 13:26 chart -rw-r--r-- 1 davidokunibm staff 2.0K Nov 6 13:26 cli-config.yml -rw-r--r-- 1 davidokunibm staff 154B Nov 6 13:26 manifest.yml drwxr-xr-x 7 davidokunibm staff 238B Nov 6 14:28 public -rw-r--r-- 1 davidokunibm staff 110B Nov 6 13:26 spec.json @dokun24
  17. Kitura CLI kitura create // interactively create a project kitura

    kit // download the KituraKit zip file @dokun24
  18. Kitura CLI kitura create // interactively create a project kitura

    kit // download the KituraKit zip file kitura idt // install IBM Cloud Developer Tools @dokun24
  19. Kitura CLI kitura create // interactively create a project kitura

    kit // download the KituraKit zip file kitura idt // install IBM Cloud Developer Tools kitura build // build the project in a local container @dokun24
  20. Kitura CLI kitura create // interactively create a project kitura

    kit // download the KituraKit zip file kitura idt // install IBM Cloud Developer Tools kitura build // build the project in a local container kitura run // run the project in a local container @dokun24