Cloud Services Client Facing App Foundation Swift Swift Standard Library Core Foundation Dispatch PWQ C libs GLibc Foundation Swift Swift Standard Library Core Foundation Dispatch Darwin C libs Client-specific Libraries App Libraries Server-specific Libraries App Libraries Driving Towards Consistent Runtime across Clients/Servers Server-side Environments (Built with Foundation & Libdispatch)
npm install –g git+https://github.com/IBM-Swift/generator-swiftserver $ yo swiftserver ? What's the name of your application? testapp ? Enter the name of the directory to contain the project: testapp ? Select the data store memory (for development purposes) create config.json create Package.swift create Sources/testapp/main.swift create Sources/Generated/ApplicationConfiguration.swift create manifest.yml create definitions/testapp.yaml Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1) Compile Swift Module 'GeneratedSwiftServer' (10 sources) Compile Swift Module 'GeneratedSwiftServer_CloudantStore' (1 sources) Compile Swift Module 'Generated' (1 sources) Compile Swift Module 'testapp' (1 sources) swift build command completed Next steps: Run the app $ .build/debug/testapp 19
book ? Custom plural form (used to build REST URL): books Let's add some book properties now. Enter an empty property name when done. ? Enter the property name: title ? Property type: string ? Required? Yes ? Default? No ? Enter the property name: author ? Property type: string ? Required? Yes ? Default? No ? Enter the property name: create models/book.json create Sources/Generated/Book.swift Compile Swift Module 'Generated' (2 sources) Compile Swift Module 'testapp' (1 sources) swift build command completed 20
Router initialized INFO: init(projectRoot:) Application.swift line 87 - Defining routes for book INFO: init(projectRoot:) Application.swift line 89 - Defining DELETE /api/books INFO: init(projectRoot:) Application.swift line 108 - Defining GET /api/books INFO: init(projectRoot:) Application.swift line 122 - Defining GET /api/books/:id INFO: init(projectRoot:) Application.swift line 158 - Defining POST /api/books INFO: init(projectRoot:) Application.swift line 203 - Defining PUT /api/books/:id INFO: init(projectRoot:) Application.swift line 264 - Defining PATCH /api/books/:id INFO: init(projectRoot:) Application.swift line 324 - Defining DELETE /api/books/:id VERBOSE: run() Kitura.swift line 71 - Starting Kitura framework... VERBOSE: run() Kitura.swift line 73 - Starting an HTTP Server on port 80... INFO: listen(on:) HTTPServer.swift line 72 - Listening on port 80 21
was harder than it should have been § Core infrastructure missing – Sockets – Security § Unsafe code required to interface with C libraries § Noone else should share our pain… 24
to create reference APIs for low-level server functionality – Adhering to Swift API design guidelines § Focus areas – Networking – Security – Web protocols 25
lacking – Building a full ORM is hard § Concurrency – Coming in Swift 5? – Actor model? § Error handling – Force unwrap is game over – Servers need more flexibility 27