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

Module rapidoid-http-fast

Low-level HTTP Framework

Built on top of Java NIO from scratch

The low-level HTTP API provides access to the extremely fast Rapidoid HTTP server components.

Rapidoid is implemented on top of Java NIO, without native libraries, nor external dependencies.

It is great to see how Java performance can match C++ and outperform all the other languages in network programming.

Designed for performance from day 1

Rapidoid was designed for high performance since its inception, and several parts of it played a critical role:

  • asynchronous I/O processing,
  • minimizing the garbage collection pressure,
  • fast object pools,
  • reusable off-heap buffers,
  • very fast and efficient HTTP parser,
  • and many other optimizations.

Rapidoid as a Network Protocol Framework

You can use Rapidoid as a Network Protocol Framework, to implement your custom TCP-based protocols.

For a quick and easy start, please take a look at the Echo protocol example.

Going low-level for ultimate performance

When you want to implement any protocol in the fastest way posible, then you need to do it on a lower level of abstraction.

Let's see how we can implement one of the fastest web servers in the world! (based on transparent TechEmpower benchmarks)

The following HTTP server features 2 web handlers:

Main.java
import org.rapidoid.net.Server;
 
public class Main {
 
    public static void main(String[] args) throws Exception {
        Server server = new CustomHttpServer().listen(5050);
 
        // Not doing any work now, so shutdown
        server.shutdown();
    }
 
}
CustomHttpServer.java
import org.rapidoid.buffer.Buf;
import org.rapidoid.http.AbstractHttpServer;
import org.rapidoid.http.HttpStatus;
import org.rapidoid.http.HttpUtils;
import org.rapidoid.http.MediaType;
import org.rapidoid.net.abstracts.Channel;
import org.rapidoid.net.impl.RapidoidHelper;
 
public class CustomHttpServer extends AbstractHttpServer {
 
    private static final byte[] URI_PLAINTEXT = "/plaintext".getBytes();
 
    private static final byte[] URI_JSON = "/json".getBytes();
 
    private static final byte[] HELLO_WORLD = "Hello, World!".getBytes();
 
    @Override
    protected HttpStatus handle(Channel ctx, Buf buf, RapidoidHelper req) {
 
        if (req.isGet.value) {
            if (matches(buf, req.path, URI_PLAINTEXT)) {
                return ok(ctx, req.isKeepAlive.value, HELLO_WORLD, MediaType.TEXT_PLAIN);
 
            } else if (matches(buf, req.path, URI_JSON)) {
                return serializeToJson(HttpUtils.noReq(), ctx, req.isKeepAlive.value, new Message("Hello, World!"));
            }
        }
 
        return HttpStatus.NOT_FOUND;
    }
 
}
Message.java
public class Message {
 
    private final String message;
 
    public Message(String message) {
        this.message = message;
    }
 
    public String getMessage() {
        return message;
    }
 
}