org.microhttp

What is it

Microhttp is an implementation of an HTTP/1.1 server.

This means that it can handle things like GET and POST requests, but not securing a connection with SSL or websocket connections.

Why use it

It is very fast and, as a result of eschewing support for most convenience features and other protocols, it has a codebase that can be reasonably read and understood fully in a day or two at most.

It discretizes requests and responses, which is a problem if you were expecting to handle file uploads or other such tasks directly, but a non-issue if you only intend to send and receive payloads of reasonable size.

In order to publish to the wider internet, you will need to have SSL. That Microhttp doesn't handle this natively isn't that much of an issue since most platforms as a service like Heroku, Railway, and Render provide this by default. As will any load balancer or properly configured nginix.

Getting Started

import org.microhttp.EventLoop;
import org.microhttp.Response;
import org.microhttp.Header;

void main() throws Exception {
    var eventLoop = new EventLoop((request, callback) -> {
        callback.accept(new Response(
            200, 
            "OK", 
            List.of(new Header("Content-Type", "text/plain")),
            "Hello, world".getBytes()
        ));
    });

    eventLoop.start();
    eventLoop.join();
}

<- Index