业务处理

Mapping mapping = Mapping.get("/foo");
Route route = Route.route(mapping)
        .handle((ctx) -> {
            // biz logic here
            ctx.response().entity("Hello Restlight!");
        });

异常处理

Mapping mapping = Mapping.get("/foo");
Route route = Route.route(mapping)
        .handle((ctx) -> {
            // biz logic here
            ctx.response().entity("Hello Restlight!");
        })
        .onError(((ctx, error) -> {
            // error occurred
        }));

Complete事件

Mapping mapping = Mapping.get("/foo");
Route route = Route.route(mapping)
        .handle((ctx) -> {
            // biz logic here
            ctx.response().entity("Hello Restlight!");
        })
        .onComplete(((ctx, t) -> {
            // request completed
        }));

异步

Route请求处理生命周期均支持基于Completablefuture的异步使用

Route route = route(get("/foo"))
        .handleAsync((ctx) ->
                CompletableFuture.runAsync(() -> {
                    // biz logic
                }))
        .onErrorAsync((ctx, throwable) ->
                CompletableFuture.runAsync(() -> {
                    // error
                }))
        .onCompleteAsync((ctx, t) ->
                CompletableFuture.runAsync(() -> {
                    // complete
                }));