Skip to content

Instantly share code, notes, and snippets.

@hhariri
Last active December 21, 2015 21:59
Show Gist options
  • Save hhariri/6372080 to your computer and use it in GitHub Desktop.
Save hhariri/6372080 to your computer and use it in GitHub Desktop.
data class Customer(val name: String, val email: String, val country: String)
val customerList = object : ArrayList<Customer>() {
}
fun main(args: Array<String>) {
// fill up some dummy customers
customerList.add(Customer("Joe Smith", "[email protected]", "UK"))
customerList.add(Customer("Jack Jones", "[email protected]", "US"))
customerList.add(Customer("Maria Gonzalez", "[email protected]", "Spain"))
// create server
val appServer = AppServer()
// enable content negotiation
appServer.negotiateContent()
// setup routes
appServer.get("/customers", listCustomers)
appServer.get("/customer/:id", getCustomerById)
appServer.post("/customer", createCustomer)
// start server
appServer.start()
}
// implement different route handlers
val listCustomers : RouteHandler.() -> Unit = {
response.send(customerList)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment