Saturday, 25 June 2016

Kotlin + Maven + Spark

I have created a demo app, with Kotlin and Spark using maven as the build tool. Check it out at

Mixing Kotlin with Spark really allows for some concise yet type safe code. Below is an example of routing in the app.

import app.Conf.view
import spark.Route
import spark.Spark.*
import java.util.*

fun main(args: Array<String>){

    get("/",        index)
    get("/about",   about)
    get("/contact", contact)

val index   = Route { req, res -> view("index")  }
val about   = Route { req, res -> view("about") }

val contact = Route { req, res ->
   val map = HashMap<String, Any>()
   map["telNo"] = "0123456";
   view("contact", model = map)

No comments:

Post a Comment