val handler = Router {
get("/", fun(): Handler = {
Response().text("Hello, world")
})
get("/<a>/<b>/<c>", fun(a: Int, b: Int, c: Int): Handler = {
Response().json(J.obj("sum" to J.num(a + b + c)))
})
}.handler()
Server(handler).listen(3000)
It has a lot of features half-stubbed out to a hobbyware level from a type-safe router to content negotiation to JSON decoder combinators.
I was in the market for a statically-typed language to use on the server and gave Kotlin a shot.
After rewriting an old, large log-parsing program, I was impressed with Kotlin's mix of simplicity and expressiveness. The designers definitely spent some quality hammock time.
I wrapped Jetty's `(Request, Response) -> Unit` signature in a `(Request) -> Response` signature which I always liked because it's easier to test and it means middleware becomes a higher-order function `((Req) -> Res) -> ((Req) -> Res)`.
It has some goofy abstractions, too, and plenty of `// TODO:`'s in the code. I couldn't even figure out how to get it working with jRebel much less roll my own hot reload.
But I think I got it to a point where it might be interesting to other weekend-ware warriors.