Rapidoid - Extremely Fast, Simple and Powerful Java Web Framework!

Rapidoid consists of several modules which can be used separately or together:
Add rapidoid-render as Maven dependency:
<dependency>
    <groupId>org.rapidoid</groupId>
    <artifactId>rapidoid-render</artifactId>
    <version>5.3.4</version>
</dependency>
docker run rapidoid --help
Module rapidoid-render

Rapidoid's template engine

  • Starting from v5.1, Rapidoid includes new templating engine.
  • Basically, it is very similar to Mustache, with the following differences.
  • 1. Using ${x} instead of {{x}}. This avoids collision of the {{x}} tags with the front-end libraries (e.g. Angular).
  • 2. Supporting additional {{?x}}...{{/x}} tag for if. The traditional {{#x}}...{{/x}} remains unchanged, having both foreach and if semantics.
  • 3. Providing text alternative if the value if not available e.g. ${x|something else}.
// The handler for /msg returns the model
// The default view name is msg
// So the corresponding template is templates/msg.html
On.page("/msg").mvc(() -> {
    return U.map("count", 12, "oki", GUI.btn("OK"));
});
 
// A custom view name can be assigned.
// In this case the default view name is abc,
// but a custom view name msg was specified
On.get("/abc").view("msg").mvc((Req req, Resp resp) -> {
    return U.map("count", 100, "oki", "");
});
templates/msg.html
<p>
    You have <span class="badge">${count}</span> new messages.
</p>
 
@{oki}
GET /msg

You have 12 new messages.

GET /abc

You have 100 new messages.

HTTP server routes information:

Verb Path Zone Content type MVC View name Roles
GET /abc main html msg
GET POST /msg main html msg

MVC Helper API (in interface Resp):

Resp view(String viewName)
Sets a custom name of the view (V from MVC) of the HTTP response.
This also sets mvc to true.
The default view name equals the request path without the "/" prefix, except for the "/" path, where the view name is "index".
E.g. "/abc" -> "abc", "/" -> "index", "/my/books" -> "my/books".
String view()
Gets the (default or customized) name of the view (V from MVC) of the HTTP response.
The default view name equals the request path without the "/" prefix, except for the "/" path, where the view name is "index".
E.g. "/abc" -> "abc", "/" -> "index", "/my/books" -> "my/books".
Resp noView()
Disables the view rendering for the target MVC route. The page decorator remains enabled.
Map<String, Object> model()
Provides read/write access to the model (M from MVC) that will be rendered by the view renderer.
Resp model(String name, Object value)
Sets an attribute of the model (M from MVC) that will be rendered by the view renderer.