RESTful service one-liner

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 Zone Content type MVC View name Roles
GET /size main json

Project setup with Maven

To run the example, you need to create a new Java 8 project and configure it properly using Maven:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
 
    <groupId>com.example</groupId>
    <artifactId>my-example</artifactId>
    <version>1.0.0-SNAPSHOT</version>
 
    <dependencies>
        <dependency>
            <groupId>org.rapidoid</groupId>
            <artifactId>rapidoid-quick</artifactId>
            <version>5.3.5</version>
        </dependency>
    </dependencies>
 
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
 
</project>

Building the project with Maven is easy:
mvn package