How to Create a REST API With Helidon SE and Java?

Hello everyone, Today, we will show you how to create a simple REST API with Helidon SE 2.5.0 and Java 17.

Quick Overview:

  • Helidon SE is designed to be a microframework that fortifies the reactive programming model. Helidon SE features three core APIs to engender a microservice -- a web server, configuration, and security -- for building microservices-predicated applications. 
  • Helidon's web server is an asynchronous and reactive API that runs on top of Netty. The WebServer interface includes support for configuration, routing, error handling, and building metrics and health endpoints.
  • The Config loads and processes configuration properties( or application.yaml) in key/value format. 
  • The Security class provides support for authentication, sanction, and audit.
Let's begin,

Final Project Directory:

Maven [pom.xml]:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=""


<description>Demo project for Helidon SE</description>




import java.util.Collections;
import java.util.concurrent.atomic.AtomicReference;
import javax.json.Json;
import javax.json.JsonBuilderFactory;
import io.helidon.config.Config;
import io.helidon.webserver.Routing.Rules;
import io.helidon.webserver.ServerRequest;
import io.helidon.webserver.ServerResponse;
import io.helidon.webserver.Service;

public class HelloService implements Service {

private static final JsonBuilderFactory JSON = Json.
private final AtomicReference<String> greeting =
new AtomicReference<>();

HelloService(Config config) {

public void update(Rules rules) {
rules.get("/", this::getDefaultMessageHandler);

private void getDefaultMessageHandler
(ServerRequest request, ServerResponse response) {
sendResponse(response, "Knowledgefactory");

private void sendResponse
(ServerResponse response, String name) {
var message = String.format("%s %s!",
greeting.get(), name);
var returnObject = JSON.
add("message", message).build();

app.message=Greetings from



import java.util.logging.Logger;
import io.helidon.common.reactive.Single;
import io.helidon.config.Config;
import io.helidon.webserver.Routing;
import io.helidon.webserver.WebServer;

public class HelidonSeRestHelloWorldApplication {

private static final Logger LOGGER = Logger.

public static void main(final String[] args) {

private static Single<WebServer> startServer() {

// Load the default configuration using the
// reate() method.
var config = Config.create();

* Helidon's web server is an asynchronous and
* reactive API that runs on top of
* Netty. The WebServer interface includes
* support for configuration, routing,
* error handling, and building metrics
* and health endpoints.
var server = WebServer.

// Start web server
var webserver = server.start();

webserver.thenAccept(ws -> {"Web server started! http://localhost:"
+ ws.port() + "/hello");
thenRun(() ->"Web server is down!"));
}).exceptionallyAccept(t -> {
LOGGER.severe("Web startup failed: "
+ t.getMessage());

return webserver;

private static Routing createRouting(Config config) {

var helloService = new HelloService(config);

return Routing.builder()

.register("/hello", helloService).build();

Local Setup and Run the application

Step1: Download or clone the source code to a local machine. - Click here

Step2: mvn clean install

Step3: Run the Main java application

INFO: Web server started! http://localhost:9080/hello

 Download the source code

Popular posts from this blog

Learn Java 8 streams with an example - print odd/even numbers from Array and List

Java Stream API - How to convert List of objects to another List of objects using Java streams?

Spring Boot + Mockito simple application with 100% code coverage

Registration and Login with Spring Boot + Spring Security + Thymeleaf

Java, Spring Boot Mini Project - Library Management System - Download

Spring boot video streaming example-HTML5

ReactJS, Spring Boot JWT Authentication Example

Java - Blowfish Encryption and decryption Example

Custom Exception Handling in Quarkus REST API

Spring Boot + OpenCSV Export Data to CSV Example