Swift is a robust language for mobile but cloud development opens the door to new opportunities for today's top app developers. Integrating projects to backend systems can sometimes be problematic, requiring new tools and skills. It doesn't have to be; end-to-end Swift opens the door to radically simpler app dev so we can all focus on the engagement. This session will describe the work that's been done to bring Swift to the server, both in terms of efforts in the Swift.org projects, and with implementation of server frameworks, and show you how you can quickly create and deploy applications with both server and client components.
Presented by Chris Bailey at the Swift Summit, Nov 7th 2016
24. @Chris__Bailey | Swift@IBM #swiftsummit
Lockheed Martin
Ground Software
Nasa Jet Propulsion Laboratory
Trajectory Calculation Software
SIS
(Software Interface Specification)
Total Impulse
pounds-seconds
(United States Customary Unit)
newton-seconds
(International System of Units)
11.488
27. @Chris__Bailey | Swift@IBM #swiftsummit
Siloed Development
API
Specification
Collaborate
on API
Collaborate
on API
Create
Deploy
Create
Deploy
28. @Chris__Bailey | Swift@IBM #swiftsummit
Collaborate
on Project
Collaborate
on Project
Collaborative Development
Deploy DeployGenerate
API
Specification
29. @Chris__Bailey | Swift@IBM #swiftsummit
Swift Development
Collaborate on
Swift Project
Deploy DeployGenerate
Swagger API
Specification
Collaborate on
Swift Project
33. @Chris__Bailey | Swift@IBM #swiftsummit
Server / Cloud DeploymentServer / Cloud DeploymentApple Client Deployment
Client Facing App
Client-Specific
Libraries
Kitura Web Framework
Swift
Standard
Library
Foundation Dispatch
Swift
Standard
Library
Foundation Dispatch
Networking
Security
HTTPParsing
Application
Libraries
Application Specific Cloud Services
Server-Specific Libraries
Application
Libraries
Consistent
Runtime across
Clients/Servers
Kitura-based Server!
Built with Dispatch &
Foundation
Swift
“Server”
APIs
Application
Libraries
36. @Chris__Bailey | Swift@IBM #swiftsummit
Create an Application
First, create a new project directory:
$ mkdir myFirstProject
Next, create a new Swift project using the Swift Package Manager.
$ cd myFirstProject
$ swift package init —-type executable
In Package.swift, add Kitura as a dependency for your project.
import PackageDescription
let package = Package(
name: "myFirstProject",
dependencies: [
.Package(url: "https://github.com/IBM-Swift/Kitura.git", majorVersion: 1, minor: 0)
])
37. @Chris__Bailey | Swift@IBM #swiftsummit
Create an Application
In Sources/main.swift, add the following code.
import Kitura
// Create a new router
let router = Router()
// Handle HTTP GET requests to /
router.get("/") {
request, response, next in
response.send("Hello, World!")
next()
}
// Add an HTTP server and connect it to the router
Kitura.addHTTPServer(onPort: 8090, with: router)
// Start the Kitura runloop (this call never returns)
Kitura.run()
38. @Chris__Bailey | Swift@IBM #swiftsummit
Deploy an Application
Open your browser at http://localhost:8090
Compile and run your application:
$ swift build
$ .build/debug/myFirstProject
42. @Chris__Bailey | Swift@IBM #swiftsummit
Using Cloud Tools
http://cloudtools.bluemix.net
• Deployment made easy
• Clone, code, push
• Demo projects to try
43. @Chris__Bailey | Swift@IBM #swiftsummit
http://www.kitura.io/en/resources/tutorials.html
Tutorials
• Creating a Todo-List Backend
• Adding Authentication with Kitura-Credentials
• Adding Sessions with Kitura-Session
• Using Templating Engines with Kitura
• Enabling SSL/TLS on Kitura
• Using FastCGI with Kitura
• Special Types of Response Handlers
• Parsing Requests