Mu-Server API Documentation
Mu-Server is a modern, lightweight web server library for Java.
An HTTP server is created by creating a server builder, such as MuServerBuilder.httpsServer()
and then calling MuServerBuilder.start()
.
Handlers are added to the builder with the MuServerBuilder.addHandler(io.muserver.MuHandler)
or MuServerBuilder.addHandler(io.muserver.Method, java.lang.String, io.muserver.RouteHandler)
methods.
Rest resources can be created by using the RestHandlerBuilder.restHandler(java.lang.Object...)
builder.
Hello, World
The following creates a server on HTTPS using a self-signed certificate, bound to a random port:
import io.muserver.MuServer;
import io.muserver.MuServerBuilder;
public class HelloServer {
public static void main(String[] args) {
MuServer server = MuServerBuilder.httpsServer()
.addHandler((request, response) -> {
response.write("Hello world");
return true;
})
.start();
System.out.println("Server started at " + server.uri());
}
}
More examples
For more documentation including the Maven artifact information, see muserver.io
Package | Description |
---|---|
io.muserver |
This package contains the main API of mu-server, for example the server builders, request and response objects.
|
io.muserver.handlers |
Some pre-built handlers for common tasks such as file handling.
|
io.muserver.openapi |
A model of the Open API spec, which is used internally when creating documentation for JAX-RS services.
|
io.muserver.rest |
This package contains the JAX-RS implementation for mu-server.
|