WebServer Introduction

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

Maven Coordinates

To enable WebServer add the following dependency to your project’s pom.xml (see Managing Dependencies).

<dependency>
    <groupId>io.helidon.webserver</groupId>
    <artifactId>helidon-webserver</artifactId>
</dependency>
Copied

Quick Start

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

    public static void main(String[] args) {
        WebServer webServer = WebServer
                .create(Routing.builder()
                                .any((req, res) -> res.send("It works!"))) 
                .start() 
                .await(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 runtime exceptions.
  • The server is bound to a random free port.