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

Rapidoid consists of several modules which can be used separately or together:
Add rapidoid-quick as Maven dependency:
<dependency>
    <groupId>org.rapidoid</groupId>
    <artifactId>rapidoid-quick</artifactId>
    <version>5.1.9</version>
</dependency>
Getting started with Rapidoid
  • For a quick start please use the rapidoid-quick module.
  • It includes rapidoid-web, Hibernate, Logback, Hibernate Validator and MySQL Connector.

Running this single line of code will start a web server embedded in your application.

By default, the server listens on port 8888 and address 0.0.0.0 (matching any IP address).

Navigating to http://localhost:8888/size?msg=abc will return 3.

// On GET /size return the length of the "msg" parameter
On.get("/size").json((String msg) -> msg.length());
GET /size?msg=abc
3

HTTP server routes information

Verb Path Segment Content type MVC View name Roles
GET /size main json
// On GET /hi or POST /hi return a "Hello World" web page
On.page("/hi").mvc("Hello <b>world</b>!");
config.yml
app:
  brand: 'Cool app!'
  title: 'the head title'
  search: true
  menu:
    Home: /
    Portfolio: /portfolio
    About:
      About Us: /about
      About You: /

Let's send some HTTP requests and check the results:

GET /hi
Hello world!

HTTP server routes information

Verb Path Segment Content type MVC View name Roles
GET POST /hi main html hi
On.address("127.0.0.1").port(9999);
 
On.get("/x").json("x"); // continue with normal setup
// 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 Segment 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".
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.
Book.java
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.validation.constraints.NotNull;
 
@Entity
public class Book {
 
    @Id
    @GeneratedValue
    public Long id;
 
    @NotNull
    public String title;
 
    public int year;
 
}
Main.java
import org.rapidoid.annotation.Valid;
import org.rapidoid.jpa.JPA;
import org.rapidoid.setup.App;
import org.rapidoid.setup.On;
 
public class Main {
 
    public static void main(String[] args) {
        App.bootstrap(args).jpa(); // bootstrap JPA
 
        On.get("/books").json(() -> JPA.of(Book.class).all()); // get all books
 
        On.post("/books").json((@Valid Book b) -> JPA.save(b)); // insert new book if valid
    }
 
}

Let's send some HTTP requests and check the results:

POST /books {"title":"Java Book","year":2016}
{"id":1,"title":"Java Book","year":2016}
GET /books
[{"id":1,"title":"Java Book","year":2016}]
POST /books {"year":2004}
{"error":"Validation failed: Book.title (may not be null)","code":422,"status":"Unprocessable Entity"}
GET /books
[{"id":1,"title":"Java Book","year":2016}]

HTTP server routes information

Verb Path Segment Content type MVC View name Roles
GET /books main json
POST /books main json