RoutingEngine
is part of
Environment
and it's used to
register Route
or
RouteProvider
instances.
void init(Environment environment) {
environment.routingEngine()
.registerAutoRoute(Route.sync("GET", "/ping", requestContext -> "pong"))
.registerAutoRoutes(new MyResource());
}
The implementation of MyResource
as a class by itself.
class MyResource implements RouteProvider {
@Override
public Stream<? extends Route<? extends AsyncHandler<?>>> routes() {
return Stream.of(
Route.sync("GET", "/v1/address/<name>", requestContext -> "!"/* do work */),
Route.sync("PUT", "/v1/address/<name>", requestContext -> "!"/* do work */)
);
}
}
Say you have defined two routes that overlap in a way that makes one of them a specific case of the other more general one. An example of such an overlap is:
/foo/bar
/foo/<arg>
Route 2 can match calls to /foo/bar
too, thus making route 1 a special case of route 2. In this
case, the RoutingEngine
will route to the more specific routes before more general ones.
Use /foo/<arg:path>
to match a path parameter, that may include slashes.