请求处理
业务处理
Mapping mapping = Mapping.get("/foo");
Route route = Route.route(mapping)
.handle((request, response) -> {
// biz logic here
response.sendResult("Hello Restlight!".getBytes(StandardCharsets.UTF_8));
});
异常处理
Mapping mapping = Mapping.get("/foo");
Route route = Route.route(mapping)
.handle((request, response) -> {
// biz logic here
response.sendResult("Hello Restlight!".getBytes(StandardCharsets.UTF_8));
})
.onError(((request, response, error) -> {
// error occurred
}));
Complete事件
Mapping mapping = Mapping.get("/foo");
Route route = Route.route(mapping)
.handle((request, response) -> {
// biz logic here
response.sendResult("Hello Restlight!".getBytes(StandardCharsets.UTF_8));
})
.onComplete(((request, response, t) -> {
// request completed
}));
异步
Route
请求处理生命周期均支持基于Completablefuture
的异步使用
Route route = route(get("/foo"))
.handleAsync((request, response) ->
CompletableFuture.runAsync(() -> {
// biz logic
}))
.onErrorAsync((request, response, throwable) ->
CompletableFuture.runAsync(() -> {
// error
}))
.onCompleteAsync((request, response, t) ->
CompletableFuture.runAsync(() -> {
// complete
}));
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.
Last modified March 10, 2022: introduce docsy as the website framework and add docs-v1.0.0 (#120) (79630ff)