package leigh.esp.sdk.service.example;

import leigh.eo.EO;
import leigh.esp.sdk.service.MicroService;
import leigh.esp.sdk.service.MicroServiceEnvironment;
import leigh.mecha.fabric.HandlerStatus;
import leigh.mecha.http.server.WebTransaction;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * This is an example Enhanced Services Platform (ESP) microservice. The ultimate goal of this partcicular example
 * is to become as short as possible from a lines-of-code perspective.
 *
 * @author Alex Leigh
 */
public class ExampleService extends MicroService {
    public ExampleService(EO cfg) throws IOException {
        super(cfg);
    }

    @Override
    public HandlerStatus handlePrefixedWebRequest(WebTransaction request) throws Throwable {
        request.httpServletResponse.setContentType("text/plain");
        request.httpServletResponse.getOutputStream().write("Hello".getBytes(StandardCharsets.UTF_8));
        return HandlerStatus.BREAK;
    }

    public static void main(String args[]) throws IOException {
        new ExampleService(MicroServiceEnvironment.getCfg(args)).run();
    }
}
