Examples

These examples show the current public API.

Health

KissServer server = KissServer.create();
server.get("/health", ctx -> ctx.text("OK"));
server.start(8080).await();

For a fixed health response, prefer the fast path:

server.fastGet("/health", FastResponses.text("OK"));

Path Parameter

server.get("/users/{id}", ctx -> {
    String id = ctx.pathParam("id");
    return ctx.text("User " + id);
});

POST Echo

server.post("/echo", ctx -> ctx.text(ctx.bodyAsString()));

Query String

server.get("/search", ctx -> ctx.text(ctx.request().queryString()));

Header Access

server.get("/agent", ctx -> {
    String agent = ctx.request().header("User-Agent");
    return ctx.text(agent == null ? "" : agent);
});

Custom Status

server.get("/missing", ctx -> ctx.text(HttpStatus.NOT_FOUND, "Missing"));

Configured Server

ExecutorService executor = Executors.newCachedThreadPool();

ServerConfig config = ServerConfig.builder()
        .port(8080)
        .executor(executor)
        .maxConnections(10_000)
        .build();

KissServer.create(config)
        .get("/health", ctx -> ctx.text("OK"))
        .start();

Fast Response

server.fastGet("/health", FastResponses.text("OK"));

JSON Response

String json = "{\"message\":\"hello\"}";
server.get("/json", ctx -> Response.body(HttpStatus.OK, ContentType.JSON, json, StandardCharsets.UTF_8));

Optional JDK 21 Virtual Threads

ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor();

ServerConfig config = ServerConfig.builder()
        .port(8080)
        .executor(executor)
        .build();

Keep this call in application code. KissServer main source compiles on Java 17.