With open source Swift, Apple has created a new range of possibilities. You can now take existing knowledge and code and apply then to web application development.
This talk will show you how you can reuse existing skills to build and deploy your first web service in Swift.
16. /// Format the given string for presentation
func formatForDate(date: NSDate) -> String {
let formatter = NSDateFormatter()
formatter.formatString = "DD MM yyyy"
return formatter.stringForDate(date)
}
46. let router = Router()
router.get("/users/:username") { request, response, next in
let username = request.params["username"] ?? "(nil)"
try response.status(HttpStatusCode.OK).send("Hello (username)")
}
let server = HttpServer.listen(8090, delegate: router)
Server.run()
49. $ curassow --workers 5
[INFO] Listening at http://localhost:8080 (65416)
[INFO] Booting worker process with pid: 65417
[INFO] Booting worker process with pid: 65418
[INFO] Booting worker process with pid: 65419
[INFO] Booting worker process with pid: 65420
[INFO] Booting worker process with pid: 65421
64. Redis (Redbird)
let client = try Redbird(config: ...)
// Set name to MCE
try client.command("SET", params: ["name", "MCE"])
// Get the name
try client.command("GET", params: ["name"])
65. PostgreSQL
let connection = Connection(host: "localhost", databaseName: "db")
try connection.open()
let usernames = try connection.execute("SELECT username FROM users").map {
try $0.data("username")
}
68. describe("a person") {
let person = Person(name: "Kyle")
$0.it("has a name") {
try expect(person.name) == "Kyle"
}
$0.it("returns the name as description") {
try expect(person.description) == "Kyle"
}
}