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

Be Your Own Backend Developer

Be Your Own Backend Developer

Presentation I gave at the Code Mobile conference in Chester.

Abizer Nasir

April 18, 2017
Tweet

More Decks by Abizer Nasir

Other Decks in Programming

Transcript

  1. You can create compiled binaries with the Swift Package Manager

    and run them from the command line. 6/37 — CodeMobile 2017
  2. Why ||Do I|| Do You Want to Be a Backend

    Developer? → It’s fun to add a new skill to the toolbox. → Provide real time data during development. → Hackdays. → Help the current backend team. → Become a full stack native app developer. 8/37 — CodeMobile 2017
  3. Swift on the Server, really means Swift on Linux, eventually

    maybe even Windows. 9/37 — CodeMobile 2017
  4. Low Memory! Memory Usage (MB)! (lower is better)! Swift @

    IBM http://benchmarksgame.alioth.debian.org/u64q/performance.php?test=spectralnorm! 11/37 — CodeMobile 2017
  5. Performant Applications! Duration (s)! (lower is better)! Swift @ IBM

    http://benchmarksgame.alioth.debian.org/u64q/performance.php?test=spectralnorm! 12/37 — CodeMobile 2017
  6. Setting up a Server → Create an executable Package with

    the Swift Package Manager. → Define the dependencies for the server, databases, template engine, logging... → Define the routes and specify the port to listen to requests on. → Build and run the project. 13/37 — CodeMobile 2017
  7. Swift is not the same everywhere. #if os(OSX) import Darwin

    public let random: (Int) -> Int = { Int(arc4random_uniform(UInt32($0))) } #else import Glibc public let random: (Int) -> Int = { while true { let x = Glibc.random() % $0 let y = Glibc.random() % $0 guard x == y else { return x } } } #endif 15/37 — CodeMobile 2017
  8. You could run it locally on your Mac, or another

    network attached Mac. 16/37 — CodeMobile 2017
  9. Set up or get a Linux box, set up Swift

    use your own editor, and terminal set up. 17/37 — CodeMobile 2017
  10. Docker seems to be the current best practice. Run the

    app in the container, edit the project in Xcode. IBM have an almost complete version of Foundation and a complete version of Dispatch that matches those available on macOS. ibmcom/swift-ubuntu 18/37 — CodeMobile 2017
  11. If you want to see if your Foundation code will

    run on Linux, you could run a REPL inside your docker container and try out some code. 19/37 — CodeMobile 2017
  12. Frameworks There are choices. All open source → Kitura →

    Vapor → Perfect 22/37 — CodeMobile 2017
  13. Routing This is the simplest part, the syntax varies between

    frameworks but essentially attach code to an endpoint. 23/37 — CodeMobile 2017
  14. Kitura import Kitura // Create a new router let router

    = Router() router.get("/") { request, response, next in response.send("Hello, World!") next() } Kitura.run() 24/37 — CodeMobile 2017
  15. Vapor import Vapor let drop = Droplet() drop.get("/hello") { _

    in return "Hello Vapor" } drop.run() 25/37 — CodeMobile 2017
  16. → Pick one and try it. → You can even

    run Vapor with a Kitura server. → There are plugins for almost anything you want to do. Security, databases, sockets, templates, Logging, 26/37 — CodeMobile 2017
  17. Deployment Kitura applications can be served from IBM’s Bluemix. Using

    a provided app or a command line application 27/37 — CodeMobile 2017
  18. Deployment Alternatively, Deploy to Heroku with a custom Buildpack. $

    heroku create --buildpack https://github.com/ kylef/heroku-buildpack-swift.git 28/37 — CodeMobile 2017
  19. Summary You get to work mainly with. the language and

    tools you’re used to in a reasonably performant environment. 29/37 — CodeMobile 2017
  20. Pick a framework. You’ll mostly be using dependencies, so there

    isn’t much code to rewrite. 30/37 — CodeMobile 2017
  21. You have greater scope for your own projects, maybe even

    client projects. 31/37 — CodeMobile 2017