<dependency>
<groupId>org.http4k</groupId>
<artifactId>http4k-core</artifactId>
<version>3.0.0-alpha2</version>
</dependency>
import org.http4k.core.HttpHandler;
import org.http4k.core.Request;
import org.http4k.core.Response;
public class MyHttpHandler implements HttpHandler {
@Override
public Response handle(Request request) {
return Response.create(200).body("Hello, World!");
}
}
import org.http4k.server.Http4kServer;
import org.http4k.server.SunHttp;
public class MyHttpServer {
public static void main(String[] args) {
Http4kServer server = SunHttp.start(8000, httpHandler);
System.out.println("Server started");
}
}
import org.http4k.core.Filter;
import org.http4k.core.Methods;
import org.http4k.core.Request;
import org.http4k.core.Response;
import org.http4k.core.Route;
import org.http4k.core.RoutingHttpHandler;
import org.http4k.core.Status;
public class MyRouter {
public static void main(String[] args) {
HttpHandler httpHandler = Filter
RoutingHttpHandler routes = Route.on(Methods.GET).to((Request request) -> {
return Response.create(Status.OK).body("GET Request");
});
HttpHandler router = routes.then(httpHandler);
Http4kServer server = SunHttp.start(8000, router);
System.out.println("Server started");
}
}