Java8异步HTTP服务器:Bayou HttpServer
jopen
10年前
Bayou HttpServer就一个基于Java8开发的嵌入式,异步HTTP服务器。
一个HttpHandler会为每一个传入的HTTP请求产生响应。
public class MyHandler implements HttpHandler { @Override public Async<HttpResponse> handle(HttpRequest request) { return HttpResponse.text(200, "Hello World"); }
利用handler创建和启动一个 HttpServer
:
public static void main(String... args) throws Exception { HttpHandler handler = new MyHandler(); HttpServer server = new HttpServer(handler); server.conf().trafficDump(System.out::print); server.start(); }