Reliable Server Side Swift ✭ Make Apache great again!
Minor adjustments, the main feature being a demo of a typesafe-select in mods_baredemo.
dbd.select("SELECT * FROM pets") { (name : String, count : Int?) in
req.puts("<tr><td>\(name)</td><td>\(count)</td></tr>")
}
No manual mapping required, the required static Swift types are the closure types.
As part of mod_swift we have been shipping mods_todomvc. Which is an implementation of a Todo-Backend, a simple JSON API to access and modify a list of todos. This release takes Todo-Backend one step further: Access the todos using CalDAV!
That's it. Demos how to implement a basic CalDAV/CardDAV server using Swift.
We prefer the Elephant, a lot. It is the right thing.
mod_swift 0.7.0 brings you support for accessing SQL database using Apache mod_dbd. Yes, Apache even includes SQL database support!
Enough words, this is how the code looks like:
guard let con = req.dbdAcquire() else { return ... }
guard let res = con.select("SELECT * FROM pets") else { return ... }
while let row = res.next() {
req.puts("<li>\(row[0])</li>")
}
And the config looks like so:
<IfModule dbd_module>
DBDriver sqlite3
DBDParams "/var/data/testdb.sqlite3"
</IfModule>
The release contains a very simple/basic wrapper library to make access to mod_dbd nicer, but is far from being a complete solution. Stay tuned.
This release brings support for using mod_swift on Ubuntu (presumably any Linux) and with Apache 2.4 servers installed via Homebrew.
Get ready to deploy!!!
Adds a simplistic Todo-MVC todo-backend.
Modularized the codebase. Instead of having one big project, there are now multiple. This provides both, a raw Apache API for those who want very little, and a Noze.io based Express framework which provides Node.js like convenience.
This:
let app = express(cookieParser(), session())
app.get("/express/cookies") { req, res, _ in
// returns all cookies as JSON
try res.json(req.cookies)
}
app.get("/express/") { req, res, _ in
let tagline = arc4random_uniform(UInt32(taglines.count))
let values : [ String : Any ] = [
"tagline" : taglines[Int(tagline)],
"viewCount" : req.session["viewCount"] ?? 0,
"cowOfTheDay" : cows.vaca()
]
try res.render("index", values)
}
and more.
Also: leftpad
.
Integrated a tiny subset of Noze.io. This makes writing simple handlers, well simple:
apache.onRequest { req, res in
res.writeHead(200, [ "Content-Type": "text/html" ])
try res.end("<h1>Hello World</h1>")
}
First release of our mod_swift
demo. Have fun!