WebServer Introduction

WebServer provides an asynchonous and reactive API for creating web applications. The API is inspired by popular NodeJS and Java frameworks.

Quick Start

Here is the code for a minimalist web application that runs on a random free port:

public static void main(String[] args) throws Exception {
    WebServer webServer = WebServer
            .create(Routing.builder()
                    .any((req, res) -> res.send("It works!")) 
                    .build())
            .start() 
            .toCompletableFuture()
            .get(10, TimeUnit.SECONDS); 

    System.out.println("Server started at: http://localhost:" + webServer.port()); 
}
Copied
  • For any kind of request, at any path, respond with It works!.
  • Start the server.
  • Wait for the server to start while throwing possible errors as exceptions.
  • The server is bound to a random free port.

Maven Coordinates

The Managing Dependencies page describes how you should declare dependency management for Helidon applications. Then declare the following dependency in your project:

<dependency>
    <groupId>io.helidon.webserver</groupId>
    <artifactId>helidon-webserver</artifactId> 
</dependency>
Copied
  • Dependency on WebServer.