Slide 1

Slide 1 text

1 Server-side Swift with the Kitura web framework Chris Bailey Ian Partridge IBM Runtimes Technologies, IBM Cloud 7th June 2016

Slide 2

Slide 2 text

Chris Bailey • Senior Technical Staff Member • IBM Runtime Technologies, IBM Cloud • @Chris__Bailey 2 Ian Partridge • Senior Developer • IBM Runtime Technologies, IBM Cloud • @alfa

Slide 3

Slide 3 text

Swift@IBM • The team within IBM working to • Accelerate MobileFirst development • Bring Swift to the cloud • IBM Swift Package Catalog • Kitura • IBM Swift Sandbox 3

Slide 4

Slide 4 text

Swift on Linux 4 • Swift on Linux and Darwin share: • Language, Standard Library, CoreFoundation, Dispatch • Foundation on Linux is new Swift implementation • Available on Darwin as “SwiftFoundation”

Slide 5

Slide 5 text

Swift 3.0 API Changes 5 • Swift 3.0 (should) introduce new Swift APIs for libraries • New Swift API for Dispatch • New Swift(ier) APIs for Foundation • Implicit bridging being replaced with explicit bridging

Slide 6

Slide 6 text

Swift Performance 6

Slide 7

Slide 7 text

Swift Memory Usage 7

Slide 8

Slide 8 text

Swift Performance by Memory 8

Slide 9

Slide 9 text

Isomorphic Swift Code 9 Create Swift Module Generate Swift Client APIs Kitura Server Project Swagger REST API Deploy Deploy • Same module on client and server • Local or remote API calls • Automatically created Swagger APIs

Slide 10

Slide 10 text

Kitura Web Framework What is it? New, modular, package-based web framework written in Swift Why is this cool? Empower a new generation of native mobile developers to write and deploy code into the Cloud. Developer Benefits ? Delivers core technologies needed to stand up enterprise apps on the server Enables developers to create a web application in Swift and deploy these servers on Linux and the Cloud. http://github.com/ibm-swift/kitura 10

Slide 11

Slide 11 text

Kitura Architecture 11 Web Framework Web Framework Source C Helpers & Interfaces Swift Libraries SwiftyJSON Kitura-redis Swift Binary Foundation Package Manager C Libraries Dispatch HttpParser HiRedis CURL PCRE2 Pluggable Components

Slide 12

Slide 12 text

Developing a Kitura web application 12 myProject ├── Package.swift ├── Sources │ └── main.swift └── Tests $ mkdir myProject 2. Next, initialize this project as a new Swift package 1. First, we create a new project directory $ cd myProject $ swift build --init Basic Swift package directory structure:

Slide 13

Slide 13 text

Developing a Kitura web application 13 import PackageDescription let package = Package( name: "myProject", dependencies: [ .Package(url: "https://github.com/IBM-Swift/Kitura.git", majorVersion: 0, minor: 15) ] ) 3. Add Kitura as a dependency for your project (Package.swift):

Slide 14

Slide 14 text

Developing a Kitura web application 14 Kitura.addHTTPServer(onPort: 8090, with: router) Kitura.run() let router = Router() router.get("/hello") { request, response, next in response.status(.OK).send("

Hello, World!

").end() } 6. Create and start an HTTPServer: 4. Add a router and a path: router.get("/hello.json") { request, response, next in response.status(.OK).send(json: JSON(["Hello": "World!"])).end() } 5. Add a JSON data route

Slide 15

Slide 15 text

Developing a Kitura web application 15 import Kitura let router = Router() router.get("/hello") { request, response, next in response.status(.OK).send("

Hello, World!

").end() } router.get("/hello.json") { request, response, next in response.status(.OK).send(json: JSON(["Hello": "World!"])).end() } Kitura.addHTTPServer(onPort: 8090, with: router) Kitura.run() 7. Sources/main.swift should now look like this:

Slide 16

Slide 16 text

Developing a Kitura web application 16 Linux: swift build -Xcc –fblocks Mac OS X: swift build -Xcc -fblocks -Xswiftc -I/usr/local/include -Xlinker -L/usr/local/lib 8. Compile: $ .build/debug/myFirstProject & 9. Run: 10. Open your browser: http://localhost:8090/hello http://localhost:8090/ http://localhost:8090/hello.json

Slide 17

Slide 17 text

Get started with Kitura • http://github.com/IBM-Swift/Kitura-Sample • `make run` • http://github.com/IBM-Swift/Kitura-Starter-Bluemix • `cf push` • http://github.com/IBM-Swift/swift-watson-sdk 17

Slide 18

Slide 18 text

IBM Swift Package Catalog • https://swiftpkgs.ng.bluemix.net/ • Find, explore and share packages from the open-source Swift ecosystem • Explore dependencies • Submit your own packages 18

Slide 19

Slide 19 text

IBM Swift Sandbox • Interactive sandbox for rapid prototyping and experimentation in Swift • Saves your work • Supports multiple versions of Swift • Responsive design 19 https://swiftlang.ng.bluemix.net/

Slide 20

Slide 20 text

Find out more 20 https://developer.ibm.com/swift/ The Swift@IBM devCenter Join IBM Swift Engineering and learn the latest news