Slim Play app
Wanna build a really, really slim Play project?
This project demonstrates how you can easily build a non-blocking, threadsafe, and fast Play app without having to
use the default routes
file. The end-result should be familiar territory for people who are used to the simplicity of Sinatra/Bottle
but want to take advantage of Scala's concurrent, type-safe and scalable nature.
In case you want to get up and running right away, use the following Slim-Play templates:
For Giter8: $ g8 lloydmeta/slim-play
sbt run
from the project's root directoryAll I did was:
sbt new
to generate a new Play app ($ sbt new playframework/play-scala-seed.g8 --name=slim-play
)AppLoader.scala
file in the ./app
directory, which holds an ApplicationLoader and the router, which is
super simple:val router = Router.from {
case GET(p"/hello/$to") => Action {
Ok(s"Hello $to")
}
/*
Use Action.async to return a Future result (sqrt can be intense :P)
Note the use of double(num) to bind only numbers (built-in :)
*/
case GET(p"/sqrt/${double(num)}") => Action.async {
Future {
Ok(Math.sqrt(num).toString)
}
}
}
play.application.loader=AppLoader
to ./conf/application.conf
so that Play knows to load our custom app (that
contains our simple router)The following links may be useful for further understanding on what is happening here: