public static interface Route.Before extends Route.Filter
{
before((req, rsp) -> {
// your code goes here
});
}
You are allowed to modify the request and response objects.
Please note that the before
handler is just syntax sugar for Route.Filter
.
For example, the before
handler was implemented as:
{
use("*", "*", (req, rsp, chain) -> {
before(req, rsp);
// your code goes here
chain.next(req, rsp);
});
}
A before
handler must to be registered before the actual handler you want to
intercept.
{
before((req, rsp) -> {
// your code goes here
});
get("/path", req -> {
// your code goes here
return ...;
});
}
If you reverse the order then it won't work.
Remember: routes are executed in the order they are defined and the pipeline is executed as long you don't generate a response.
Modifier and Type | Method and Description |
---|---|
void |
handle(Request req,
Response rsp)
Allows for customized handler execution chains.
|
default void |
handle(Request req,
Response rsp,
Route.Chain chain)
The
handle method of the Filter is called by the server each time a
request/response pair is passed through the chain due to a client request for a resource at
the end of the chain. |
default void handle(Request req, Response rsp, Route.Chain chain) throws Throwable
Route.Filter
handle
method of the Filter is called by the server each time a
request/response pair is passed through the chain due to a client request for a resource at
the end of the chain.
The Route.Chain
passed in to this method allows the Filter to pass on the request and
response to the next entity in the chain.
A typical implementation of this method would follow the following pattern:
Route.Chain
object (chain.next(req, rsp)
),handle
in interface Route.Filter
req
- A HTTP request.rsp
- A HTTP response.chain
- A route chain.Throwable
- If something goes wrong.Copyright © 2019. All rights reserved.