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. IBM & Server Side Swift Making Your Mobile Developers Full

    Stack By David Okun @dokun24
  2. A Brief History of Swift @dokun24

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

    is released @dokun24
  4. A Brief History of Swift • June 2014 - Swift

    is released • June 2015 - Swift on Linux is announced @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 @dokun24
  6. 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
  7. 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
  8. 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
  9. Kitura - HTTP for Swift @dokun24

  10. Kitura - HTTP for Swift • Architected like Express.js @dokun24

  11. Kitura - HTTP for Swift • Architected like Express.js •

    Written with Swift on Linux @dokun24
  12. Kitura - HTTP for Swift • Architected like Express.js •

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

    Written with Swift on Linux • Front-end templating • Persistence layer compatibility @dokun24
  14. @dokun24

  15. @dokun24

  16. @dokun24

  17. @dokun24

  18. @dokun24

  19. @dokun24

  20. Kitura 2.0 @dokun24

  21. Kitura 2.0 • KituraKit - for clients @dokun24

  22. Kitura 2.0 • KituraKit - for clients • A shiny

    new CLI @dokun24
  23. Kitura 2.0 • KituraKit - for clients • A shiny

    new CLI • Codable routing @dokun24
  24. Codable? @dokun24

  25. Codable? @dokun24

  26. Kitura 1.x Parsing @dokun24

  27. 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
  28. Kitura 1.x Parsing @dokun24

  29. 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
  30. Kitura 2.x Parsing @dokun24

  31. 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)) } }
  32. Codable Protocol @dokun24

  33. Codable Protocol • Responsible for encoding and decoding objects to

    another type, such as JSON @dokun24
  34. Codable Protocol • Responsible for encoding and decoding objects to

    another type, such as JSON • Sub-protocols: Encodable and Decodable @dokun24
  35. 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
  36. Kitura CLI @dokun24

  37. Kitura CLI • Uses Yeoman to generate projects @dokun24

  38. Kitura CLI • Uses Yeoman to generate projects • Ready

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

    made for IBM Cloud deployment • Analytics, health, OpenAPI UI @dokun24
  40. Kitura CLI @dokun24

  41. Kitura CLI brew tap ibm-swift/kitura @dokun24

  42. Kitura CLI brew tap ibm-swift/kitura brew install kitura @dokun24

  43. Kitura CLI brew tap ibm-swift/kitura brew install kitura kitura init

    @dokun24
  44. Kitura CLI @dokun24

  45. 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
  46. Kitura CLI @dokun24

  47. Kitura CLI kitura create // interactively create a project @dokun24

  48. Kitura CLI kitura create // interactively create a project kitura

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

    kit // download the KituraKit zip file kitura idt // install IBM Cloud Developer Tools @dokun24
  50. 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
  51. 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
  52. Kitura Demo @dokun24

  53. Resources @dokun24

  54. Resources • http://kitura.io @dokun24

  55. Resources • http://kitura.io • https://developer.ibm.com/swift/ @dokun24

  56. Resources • http://kitura.io • https://developer.ibm.com/swift/ • https://github.com/ibm/foodtrackerbackend @dokun24

  57. Thanks! @dokun24