Trinity is a lightweight MVC framework based on Finagle, written in Scala.
Since May 2013
- Provide MVC functions not supported by Finagle.
- Support Domain Driven-Design by non CoC(Convention over Configuration).
- You can use Actions as Controller, instead of Finagle Service.
- URLs can be mapped to action methods, like Scalatra.
- Otherwise, The Routing information can be outside of the Controller, like Play2.
- You can use Template Engine (e.g. Scalatra) with Trinity.
- Routing request to action. return's type is
scala.concurrent.Future
- Finagle's Request/Response Enhance
- Multi-part file upload
- JSON format reponse
- File resouce support
- Binding to Template Engine
- Scalate
- Velocity TBD
- FreeMarker TBD
- Thymeleaf TBD
- Testing
- Unit testing
- Integration testing
- JRebel support
- see this gist for installation. https://gist.github.com/j5ik2o/5660744
- Form
- Validation
- Persistence(e.g. RDBMS/NoSQL)
Add the following to your sbt build (Scala 2.10.x, and Scala 2.11.x):
resolvers += "Sonatype Release Repository" at "http://oss.sonatype.org/content/repositories/releases/"
libraryDependencies += "org.sisioh" %% "trinity" % "1.0.12"
resolvers += "Sonatype Snapshot Repository" at "http://oss.sonatype.org/content/repositories/snapshots/"
libraryDependencies += "org.sisioh" %% "trinity" % "1.0.13-SNAPSHOT"
object ScalatraLikeControllerApplication
extends ConsoleApplication {
get("/hello") {
request =>
responseBuilder.withTextPlain("Hello World!!").toFuture
}
get("/json") {
request =>
val jValue = JObject(
JField("name", JString("value"))
)
responseBuilder.withJson(jValue).toFuture
}
get("/user/:userId") {
request =>
responseBuilder.withTextPlain("userId = " + request.routeParams("userId")).toFuture
}
get( """/group/(.*)""".r, Seq("name")) {
request =>
ResponseBuilder().withTextPlain("name = " + request.routeParams("name")).toFuture
}
startWithAwait()
}
object PlayLikeApplicationForController extends ConsoleApplication {
case class MainController() extends ControllerSupport {
def helloWorld = SimpleAction {
request =>
responseBuilder.withTextPlain("Hello World!!").toFuture
}
def getUser = SimpleAction {
request =>
responseBuilder.withTextPlain("userId = " + request.routeParams("userId")).toFuture
}
def getGroup(name: String) = SimpleAction {
request =>
responseBuilder.withTextPlain("name = " + name).toFuture
}
}
val mainController = MainController()
override protected val routingFilter = Some(RoutingFilter.createForActions {
implicit pathPatternParser =>
Seq(
Get % "/hello" -> mainController.helloWorld,
Get % "/user/:userId" -> mainController.getUser,
Get % ("""/group/(.*)""".r -> Seq("name")) -> {
request =>
mainController.getGroup(request.routeParams("name"))(request)
}
)
})
startWithAwait()
}
$ sbt clean compile
$ sbt run
$ curl -X GET http://localhost:7070/hello
Hello!