http://skinny-framework.org/documentation/micro.html
This is a sample application which shows you how to make Sinatra-ish web applications more type-safe than Scalatra.
Scala compiler fails to comple the following code
package sample
import skinny.micro._
class SimpleApp extends TypedWebApp {
get("/hello") {
"Hello, World!"
}
}
as below:
[info] Compiling 1 Scala source to ~/workplace/typed-skinny-micro/target/scala-2.10/classes...
[error] ~/workplace/typed-skinny-micro/src/main/scala/app.scala:8: type mismatch;
[error] found : String("Hello, World!")
[error] required: skinny.micro.ActionResult
[error] (which expands to) skinny.micro.response.ActionResult
[error] "Hello, World!"
[error] ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed
Only skinny.micro.ActionResult
value can be accepted inside routing DSL blocks.
class SimpleApp extends TypedWebApp {
get("/hello") {
Ok("Hello, World!")
}
}
or
get("/hello") {
Ok(
body = "Hello, World!",
headers = Map("X-Foo-Header" -> "foo-bar-baz")
)
}
Compilation result:
[info] Compiling 1 Scala source to ~/workplace/typed-skinny-micro/target/scala-2.10/classes...
[success] Total time: 3 s, completed Feb 18, 2016 9:52:09 AM
Future-wired web controller is also available. The async routing DSL expects Future[ActionResult]
instead.
object AsyncApp extends TypedAsyncWebApp {
get("/async/hello") { implicit ctx =>
Ok("Hello, World!")
}
}
Compilation error:
[info] Compiling 3 Scala sources to ~/workplace/typed-skinny-micro/target/scala-2.11/classes...
[error] ~/workplace/typed-skinny-micro/src/main/scala/sample/AsyncApp.scala:7: type mismatch;
[error] found : skinny.micro.response.ActionResult
[error] required: scala.concurrent.Future[skinny.micro.ActionResult]
[error] (which expands to) scala.concurrent.Future[skinny.micro.response.ActionResult]
[error] Ok("Hello, World!")
[error] ^
Returning scala.concurrent.Future[skinny.micro.ActionResult]
works.
package sample
import skinny.micro._
import scala.concurrent.Future
object AsyncApp extends TypedAsyncWebApp {
get("/async/hello") { implicit ctx =>
Future { Ok("Hello, World!") }
}
}
brew install sbt
sbt ~;container:restart
The MIT License