Xitrum (original) (raw)
Features
There are comprehensive usage guides for many languages.
- Typesafe, in the spirit of Scala. All the APIs try to be as typesafe as possible.
- Async, in the spirit of Netty. Your request proccessing action does not have to respond immediately. Long polling, chunked response (streaming), WebSocket, and SockJS are supported.
- Fast built-in HTTP and HTTPS web server based on Netty(HTTPS can use Java engine or native OpenSSL engine). Xitrum’s static file serving speed is similar to that of Nginx.
- Extensive client-side and server-side caching for faster responding. At the web server layer, small files are cached in memory, big files are sent using NIO’s zero copy. At the web framework layer you have can declare page, action, and object cache in the Rails style.All Google’s best practiceslike conditional GET are applied for client-side caching. You can also force browsers to always send request to server to revalidate cache before using.
- Range requestsfor static files. Serving movie files for smartphones requires this feature. You can pause/resume file download.
- CORS support.
- Routes are automatically collected in the spirit of JAX-RS and Rails Engines. You don’t have to declare all routes in a single place. Think of this feature as distributed routes. You can plug an app into another app. If you have a blog engine, you can package it as a JAR file, then you can put that JAR file into another app and that app automatically has blog feature! Routing is also two-way: you can recreate URLs (reverse routing) in a typesafe way. You can document routes using Swagger Doc.
- Classes and routes are automatically reloaded in development mode.
- Views can be written in a separate Scalatetemplate file or Scala inline XML. Both are typesafe.
- Sessions can be stored in cookies (more scalable) or clustered Hazelcast (more secure). Hazelcast is recommended when using continuations-based Actions, since serialized continuations are usually too big to store in cookies. Hazelcast also gives in-process (thus faster and simpler to use) distribued cache and pubsub, you don’t need separate cache and pubsub servers.
- jQuery Validation is integrated for browser side and server side validation.
- i18n using GNU gettext. Translation text extraction is done automatically. You don’t have to manually mess with properties files. You can use powerful tools like Poeditfor translating and merging translations. gettext is unlike most other solutions, both singular and plural forms are supported.
- Xitrum tries to fill the spectrum between Scalatraand Lift: more powerful than Scalatra and easier to use than Lift. You can easily create both RESTful APIs and postbacks. Xitrum is controller-first like Scalatra, notview-first like Lift. Most people are familliar with controller-first style.
Scalibility is easy, just throw more nodes to the pool.

Hello World example
import xitrum.Action
import xitrum.annotation.GET
@GET("url/to/HelloAction")
class HelloAction extends Action {
def execute() {
val urlToHelloActor = url[HelloActor]
respondHtml(
<xml:group>
<p>Hello {remoteIp}!</p>
<a href={urlToHelloActor}>Actor example</a>
</xml:group>
)
}
} The above action runs directly on Netty's IO thread pool. It's very fast if your action is simple. If it's more complex, avoid blocking request receiving and response responding, by running it on another thread pool, by extending xitrum.FutureAction.
Actor example
import scala.concurrent.duration._
import akka.actor.ReceiveTimeout
import xitrum.ActorAction
import xitrum.annotation.GET
@GET("url/to/HelloActor")
class HelloActor extends ActorAction {
def execute() {
log.info("Request received: " + request)
// Communicate with another actor
anotherActorRef ! "aMsg"
// Wait for the above actor to reply within 5s
context.setReceiveTimeout(5.seconds)
context.become {
case aReply =>
respondText(aReply)
case ReceiveTimeout =>
respondText("Timeout")
}
}
override def postStop() {
log.info("Connection closed or response sent")
super.postStop()
}
}Just annotate your actors and they will be accessible from web!
WebSocket example
import xitrum.{
WebSocketAction,
WebSocketText, WebSocketBinary,
WebSocketPing, WebSocketPong
}
import xitrum.annotation.WEBSOCKET
@WEBSOCKET("url/to/EchoWebSocketActor")
class EchoWebSocketActor extends WebSocketAction {
def execute() {
log.info("WebSocket onopen")
context.become {
case WebSocketText(text) =>
respondWebSocketText(text)
case WebSocketBinary(bytes) =>
respondWebSocketBinary(bytes)
case WebSocketPing =>
// Xitrum automatically sends pong for you,
// you don't have to send pong yourself
case WebSocketPong =>
// Client has received your ping
}
}
override def postStop() {
log.info("WebSocket onclose")
super.postStop()
}
}SockJS example
import xitrum.{SockJsAction, SockJsText}
import xitrum.annotation.SOCKJS
@SOCKJS("url/to/EchoSockJsActor")
class EchoSockJsActor extends SockJsAction {
def execute() {
log.info("SockJS onopen")
context.become {
case SockJsText(text) =>
respondSockJsText(text)
}
}
override def postStop() {
log.info("SockJS onclose")
super.postStop()
}
}Presentations
News
- Xitrum 3.30.1 Jan 20 2021
- Xitrum 3.30.0 Jan 18 2021
- Xitrum 3.28.18 Sep 7 2019
- Xitrum 3.28.17 Jun 4 2019
- Xitrum 3.28.16 Feb 18 2019
- Xitrum 3.28.15 Dec 9 2018
- Xitrum 3.28.14 Nov 3 2018
- Xitrum 3.28.13 Oct 17 2018
- Xitrum 3.28.12 Oct 7 2018
- Xitrum 3.28.11 Sep 2 2018
- Xitrum 3.28.10 Jul 25 2018
- Xitrum 3.28.9 May 25 2018
- Xitrum 3.28.8 Feb 27 2018
- Xitrum 3.28.7 Jan 24 2018
- Xitrum 3.28.6 Nov 25 2017
- Xitrum 3.28.5 Aug 25 2017
- Xitrum 3.28.4 May 25 2017
- Xitrum 3.28.3 Mar 28 2017
- Xitrum 3.28.2 Jan 12 2017
- Xitrum 3.28.1 Oct 2 2016
- Xitrum 3.28.0 Aug 4 2016
- Xitrum 3.27.0 Jul 18 2016
- Xitrum 3.26.2 Jun 22 2016
- Xitrum 3.26.1 May 31 2016
- Xitrum 3.26.0 Jan 09 2016
- Xitrum 3.25.0 Aug 14 2015
- Xitrum 3.24.0 May 24 2015
- Xitrum 3.23 Mar 14 2015
- Xitrum 3.22 Jan 20 2015
- Xitrum 3.21 Dec 18 2014
- Xitrum 3.20 Dec 12 2014
- Xitrum 3.19 Nov 14 2014
- Xitrum 3.18 Aug 19 2014
- Xitrum 3.17 Aug 01 2014
- Xitrum 3.16 Jul 09 2014
- Xitrum 3.15 Jul 05 2014
- Xitrum 3.14 Jun 16 2014
- Xitrum 3.13 May 23 2014
- Xitrum 2.15 Dec 25 2013