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

Configuring Rapidoid
  • Rapidoid has built-in default configuration which provides sensible defaults for many components of the framework.
  • Custom configuration can be specified through config.yml or config.yaml configuration files.
  • Profile-specified custom configuration can be specified through config-<profile-name-here>.yml or config-<profile-name-here>.yaml configuration files.
  • The configuration files will tipically be classpath resources, but they can reside in a custom-configured external folder, as well.
  • Rapidoid can also be configured through command line args or system/environment properties.
  • The custom configuration overrides the built-in default configuration.
// Let's take a look at the default configuration in Rapidoid
On.get("/").mvc(new ConfigHandler());

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

GET /

on

Key Value
port 8080
address 0.0.0.0

admin

Key Value
port same
address 0.0.0.0

app

Key Value
contextPath
home /

gui

Key Value
search
navbar
fluid
cdn auto

admin-zone

Key Value
home /_
brand <i class="fa fa-dashboard"></i> Admin Center
search
fluid
menu
Key Value
Overview /_
Routes /_routes
Configuration /_config
Deployment /_deployment
Processes /_processes
Metrics /_metrics
Manageables /_manageables
Application
Key Value
Beans /_beans
Entities /_entities
System
Key Value
Terminate / Restart /_terminate
Classpath /_classpath
Memory pool /_jmx/mempool
JVM Threads /_jmx/threads
Operating system /_jmx/os
Garbage collection /_jmx/gc
Memory /_jmx/memory
Runtime /_jmx/runtime
Classes /_jmx/classes
Compilation /_jmx/compilation

users

Key Value
admin
Key Value
roles administrator

jobs

Key Value
executor
Key Value
threads 256
scheduler
Key Value
threads 64

hibernate

Key Value
c3p0
Key Value
debug
initialPoolSize 5
minPoolSize 5
maxPoolSize 100
acquireIncrement 5
maxStatementsPerConnection 10
idleConnectionTestPeriod 300
dialect org.hibernate.dialect.HSQLDialect
connection
Key Value
driver_class org.hsqldb.jdbc.JDBCDriver
url jdbc:hsqldb:mem:public
username sa
password
hbm2ddl
Key Value
auto update

c3p0

Key Value
debug
initialPoolSize 5
minPoolSize 5
maxPoolSize 100
acquireIncrement 5
maxStatementsPerConnection 10
idleConnectionTestPeriod 300

oauth

Key Value
google
Key Value
scope profile,email
clientId YOUR_GOOGLE_CLIENT_ID_HERE
clientSecret
github
Key Value
scope user:email
clientId YOUR_GITHUB_CLIENT_ID_HERE
clientSecret
facebook
Key Value
scope public_profile,email
clientId YOUR_FACEBOOK_CLIENT_ID_HERE
clientSecret
linkedin
Key Value
scope r_basicprofile,r_emailaddress
clientId YOUR_LINKEDIN_CLIENT_ID_HERE
clientSecret

net

Key Value
address 0.0.0.0
port 8080
bufSizeKB 256
noDelay
syncBufs

http

Key Value
timeout 30000
timeoutResolution 5000
maxPipeline 10
serverName Rapidoid
mandatoryHeaders
Key Value
connection
date
server
contentType

token

Key Value
ttl 0

log

Key Value
level info
fancy

jdbc

Key Value
driver org.hsqldb.jdbc.JDBCDriver
url jdbc:hsqldb:mem:public
username sa
password

HTTP server routes information:

Verb Path Zone Content type MVC View name Roles
GET / main html index
Main.java
import org.rapidoid.config.Conf;
import org.rapidoid.env.Env;
import org.rapidoid.gui.GUI;
import org.rapidoid.setup.App;
import org.rapidoid.setup.On;
 
import java.util.Map;
 
public class Main {
    public static void main(String[] args) {
        App.bootstrap(args, "profiles=mysql,foo");
 
        On.get("/profiles").mvc(() -> GUI.display(Env.profiles()));
 
        Map<String, Object> myConfig = Conf.section("my").toMap();
        On.get("/my").mvc(() -> GUI.grid(myConfig));
    }
}
FooCtrl.java
import org.rapidoid.annotation.Controller;
import org.rapidoid.annotation.GET;
import org.rapidoid.annotation.Profiles;
 
@Controller
@Profiles("foo")
public class FooCtrl {
 
    @GET
    public String hi() {
        return "hi, FOO controller!";
    }
 
}
OtherCtrl.java
import org.rapidoid.annotation.Controller;
import org.rapidoid.annotation.GET;
import org.rapidoid.annotation.Profiles;
 
@Controller
@Profiles("default")
public class OtherCtrl {
 
    @GET
    public String hi() {
        return "hi, OTHER controller!";
    }
 
}
config-foo.yml
my:
  msg: 'hello from Foo!'
config.yml
gui:
  navbar: false
 
my:
  msg: 'hello!'
  desc: 'simple example'
GET /profiles
 mysql
 foo
 dev
GET /my
Key Value
msg hello from Foo!
desc simple example
GET /hi
"hi, FOO controller!"

HTTP server routes information:

Verb Path Zone Content type MVC View name Roles
GET /hi main json
GET /my main html my
GET /profiles main html profiles
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
    }
 
}
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;
 
}
config-default.yml
jdbc:
  driver: org.hsqldb.jdbc.JDBCDriver
  url: jdbc:hsqldb:mem:public
  username: sa
  password: ''
 
hibernate:
  dialect: org.hibernate.dialect.HSQLDialect
  connection:
    driver_class: org.hsqldb.jdbc.JDBCDriver
    url: jdbc:hsqldb:mem:public
    username: sa
    password: ''
config-dev.yml
hibernate:
  format_sql: false
  show_sql: true
 
c3p0:
  debug: true
 
hibernate:
  hbm2ddl:
    auto: update
config-mysql.yml
jdbc:
  driver: com.mysql.jdbc.Driver
  url: jdbc:mysql://localhost:3306/rapidoid
  username: root
  password: root
 
hibernate:
  dialect: org.hibernate.dialect.MySQL5Dialect
  connection:
    driver_class: com.mysql.jdbc.Driver
    username: root
    password: root
    url: jdbc:mysql://localhost:3306/rapidoid
config.yml
on:
  port: 8888
  address: 0.0.0.0
 
admin:
  port: same
  address: 0.0.0.0
 
app:
  home: /
  contextPath: /
 
gui:
  domain: ''
  brand: App
  search: false
  navbar: true
  fluid: false
  cdn: auto # in DEV mode is false, in PRODUCTION is true
  menu: {}
 
users:
  root:
    roles:
      - administrator
      - owner
    password: root # PLEASE change this

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 Zone Content type MVC View name Roles
GET /books main json
POST /books main json
On.address("127.0.0.1").port(9999);
 
On.get("/x").json("x"); // continue with normal setup
Name Desc Default value
config configuration filename prefix config
dev run in DEV mode auto-detected
production run in PRODUCTION mode auto-detected
test run in TEST mode auto-detected
secret=<SECRET> configure secret key for cryptography random
profiles=<P1,P2...> comma-separated list of application profiles (e.g. mysql,prod) the 'default' profile
on.port=<P> the default App server will listen at port P 8888
on.address=<ADDR> the default App server will listen at address ADDR 0.0.0.0
admin.port=<P> the Admin server will listen at port P same as on.port
admin.address=<ADDR> the Admin server will listen at address ADDR on.address
app.services=<S1,S2...> comma-separated list of services to bootstrap on the App server none
admin.services=<S1,S2...> comma-separated list of services to bootstrap on the Admin server none
MyApp.java
public class MyApp {
 
    public static void main(String[] args) {
        // Initialize the configuration
        App.run(args);
 
        On.get("/hi").json((Req req) -> req.data("name", "unknown"));
    }
 
}