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

    View Slide

  2. A Brief History of Swift
    @dokun24

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  9. Kitura - HTTP for Swift
    @dokun24

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  14. @dokun24

    View Slide

  15. @dokun24

    View Slide

  16. @dokun24

    View Slide

  17. @dokun24

    View Slide

  18. @dokun24

    View Slide

  19. @dokun24

    View Slide

  20. Kitura 2.0
    @dokun24

    View Slide

  21. Kitura 2.0
    • KituraKit - for clients
    @dokun24

    View Slide

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

    View Slide

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

    View Slide

  24. Codable?
    @dokun24

    View Slide

  25. Codable?
    @dokun24

    View Slide

  26. Kitura 1.x Parsing
    @dokun24

    View Slide

  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

    View Slide

  28. Kitura 1.x Parsing
    @dokun24

    View Slide

  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

    View Slide

  30. Kitura 2.x Parsing
    @dokun24

    View Slide

  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))
    }
    }

    View Slide

  32. Codable Protocol
    @dokun24

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

  36. Kitura CLI
    @dokun24

    View Slide

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

    View Slide

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

    View Slide

  39. Kitura CLI
    • Uses Yeoman to generate projects
    • Ready made for IBM Cloud deployment
    • Analytics, health, OpenAPI UI
    @dokun24

    View Slide

  40. Kitura CLI
    @dokun24

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  44. Kitura CLI
    @dokun24

    View Slide

  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

    View Slide

  46. Kitura CLI
    @dokun24

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

  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

    View Slide

  52. Kitura Demo
    @dokun24

    View Slide

  53. Resources
    @dokun24

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  57. Thanks!
    @dokun24

    View Slide