Scalatra
Jump to navigation
Jump to search
Scalatra is an HTTP micro-framework, written in the up-and-coming new language, Scala. Scalatra is used by LinkedIn, the BBC, the Guardian newspaper, games website IGN, social identity provider JanRain, the Wordnik online dictionary, and the British government’s new flagship website. It’s fast, battle-tested, and in production. This article introduces you to the simplicity of Scalatra micro-framework.
Example of web app (from Book Scalatra in Action)
package com.example.app
import org.scalatra._
import scalate.ScalateSupport
class MyScalatraServlet extends ScalatraServlet with ScalateSupport {
get(“/”) {
<html>
<body>
<h1>Hello, world!</h1>
Say <a href=“hello-scalate”>hello to Scalate</a>.
</body>
</html>
}
notFound {
// remove content type in case it was set through an action
contentType = null
// Try to render a ScalateTemplate if no route matched
findTemplate(requestPath) map { path =>
contentType = “text/html”
layoutTemplate(path)
} orElse serveStaticResource() getOrElse resourceNotFound()
}
}
browse http://localhost:8080/hello
Books
- Scalatra in Action, http://www.manning.com/carrero2/