package lc.esp.example.service;

import lc.esp.engine.ESPEngine;
import lc.mecha.fabric.HandlerStatus;
import lc.mecha.http.server.HttpTransaction;
import lc.mecha.http.server.PrefixedHandler;

import java.util.Set;

/**
 * This example service illustrates how to create an ESP-based HTTP service.
 *
 * @author Alex Leigh
 * @since mk20 (TOKYO PROTOCOL)
 */
public class ExampleService {
    public static void main(String[] args) throws Exception {
        var esp = new ESPEngine();
        esp.register(new PrefixedHandler(Set.of("/api/example")) {
            @Override
            public HandlerStatus handlePrefixedWebRequest(HttpTransaction request) throws Throwable {
                request.httpServletResponse.getOutputStream().write("Hello World\n".getBytes());
                return HandlerStatus.BREAK;
            }
        });
        esp.runDangerously();
    }
}
