public interface Routes
Modifier and Type | Method and Description |
---|---|
default Route.Collection |
after(Route.After handler,
Route.After... chain)
after
|
default Route.Collection |
after(String pattern,
Route.After handler,
Route.After... chain)
after
|
Route.Collection |
after(String method,
String pattern,
Route.After handler,
Route.After... chain)
after
|
Route.Definition |
assets(String path)
Send a static file.
|
Route.Definition |
assets(String path,
AssetHandler handler)
Send a static file.
|
Route.Definition |
assets(String path,
String location)
Send a static file.
|
default Route.Collection |
before(Route.Before handler,
Route.Before... chain)
before
|
default Route.Collection |
before(String pattern,
Route.Before handler,
Route.Before... chain)
before
|
Route.Collection |
before(String method,
String pattern,
Route.Before handler,
Route.Before... chain)
before
|
default Route.Collection |
complete(Route.Complete handler,
Route.Complete... chain)
complete
|
default Route.Collection |
complete(String pattern,
Route.Complete handler,
Route.Complete... chain)
complete
|
Route.Collection |
complete(String method,
String pattern,
Route.Complete handler,
Route.Complete... chain)
after
|
Route.Definition |
connect(String path,
Route.Filter filter)
Append a route that supports HTTP CONNECT method:
|
Route.Definition |
connect(String path,
Route.Handler handler)
Append a route that supports HTTP CONNECT method:
|
Route.Definition |
connect(String path,
Route.OneArgHandler handler)
Append route that supports HTTP CONNECT method:
|
Route.Definition |
connect(String path,
Route.ZeroArgHandler handler)
Append route that supports HTTP CONNECT method:
|
Route.Definition |
delete(String path,
Route.Filter filter)
Append a route that supports HTTP DELETE method:
|
Route.Definition |
delete(String path,
Route.Handler handler)
Append a route that supports HTTP DELETE method:
|
Route.Definition |
delete(String path,
Route.OneArgHandler handler)
Append route that supports HTTP DELETE method:
|
Route.Definition |
delete(String path,
Route.ZeroArgHandler handler)
Append route that supports HTTP DELETE method:
|
Route.Collection |
delete(String path1,
String path2,
Route.Filter filter)
Append three routes that supports HTTP DELETE method on the same handler:
|
Route.Collection |
delete(String path1,
String path2,
Route.Handler handler)
Append three routes that supports HTTP DELETE method on the same handler:
|
Route.Collection |
delete(String path1,
String path2,
Route.OneArgHandler handler)
Append three routes that supports HTTP DELETE method on the same handler:
|
Route.Collection |
delete(String path1,
String path2,
Route.ZeroArgHandler handler)
Append three routes that supports HTTP DELETE method on the same handler:
|
Route.Collection |
delete(String path1,
String path2,
String path3,
Route.Filter filter)
Append three routes that supports HTTP DELETE method on the same handler:
|
Route.Collection |
delete(String path1,
String path2,
String path3,
Route.Handler handler)
Append three routes that supports HTTP DELETE method on the same handler:
|
Route.Collection |
delete(String path1,
String path2,
String path3,
Route.OneArgHandler handler)
Append three routes that supports HTTP DELETE method on the same handler:
|
Route.Collection |
delete(String path1,
String path2,
String path3,
Route.ZeroArgHandler handler)
Append three routes that supports HTTP DELETE method on the same handler:
|
default Routes |
err(Class<? extends Throwable> type,
Err.Handler handler)
Setup a route error handler.The error handler will be executed if the current exception is an
instance of this type.
|
Routes |
err(Err.Handler err)
Setup a route error handler.
|
default Routes |
err(int statusCode,
Err.Handler handler)
Setup a route error handler.
|
Route.Definition |
get(String path,
Route.Filter filter)
Append a filter that supports HTTP GET method:
|
Route.Definition |
get(String path,
Route.Handler handler)
Append a route that supports HTTP GET method:
|
Route.Definition |
get(String path,
Route.OneArgHandler handler)
Append route that supports HTTP GET method:
|
Route.Definition |
get(String path,
Route.ZeroArgHandler handler)
Append route that supports HTTP GET method:
|
Route.Collection |
get(String path1,
String path2,
Route.Filter filter)
Append three routes that supports HTTP GET method on the same handler:
|
Route.Collection |
get(String path1,
String path2,
Route.Handler handler)
Append two routes that supports HTTP GET method on the same handler:
|
Route.Collection |
get(String path1,
String path2,
Route.OneArgHandler handler)
Append three routes that supports HTTP GET method on the same handler:
|
Route.Collection |
get(String path1,
String path2,
Route.ZeroArgHandler handler)
Append three routes that supports HTTP GET method on the same handler:
|
Route.Collection |
get(String path1,
String path2,
String path3,
Route.Filter filter)
Append three routes that supports HTTP GET method on the same handler:
|
Route.Collection |
get(String path1,
String path2,
String path3,
Route.Handler handler)
Append three routes that supports HTTP GET method on the same handler:
|
Route.Collection |
get(String path1,
String path2,
String path3,
Route.OneArgHandler handler)
Append three routes that supports HTTP GET method on the same handler:
|
Route.Collection |
get(String path1,
String path2,
String path3,
Route.ZeroArgHandler handler)
Append three routes that supports HTTP GET method on the same handler:
|
Route.Definition |
head()
Append a new route that automatically handles HEAD request from existing GET routes.
|
Route.Definition |
head(String path,
Route.Filter filter)
Append a route that supports HTTP HEAD method:
|
Route.Definition |
head(String path,
Route.Handler handler)
Append a route that supports HTTP HEAD method:
|
Route.Definition |
head(String path,
Route.OneArgHandler handler)
Append route that supports HTTP HEAD method:
|
Route.Definition |
head(String path,
Route.ZeroArgHandler handler)
Append route that supports HTTP HEAD method:
|
Routes |
map(Route.Mapper<?> mapper)
Apply the mapper to all the functional routes.
|
Route.Definition |
options()
Append a new route that automatically handles OPTIONS requests.
|
Route.Definition |
options(String path,
Route.Filter filter)
Append a route that supports HTTP OPTIONS method:
|
Route.Definition |
options(String path,
Route.Handler handler)
Append a route that supports HTTP OPTIONS method:
|
Route.Definition |
options(String path,
Route.OneArgHandler handler)
Append route that supports HTTP OPTIONS method:
|
Route.Definition |
options(String path,
Route.ZeroArgHandler handler)
Append route that supports HTTP OPTIONS method:
|
Route.Definition |
patch(String path,
Route.Filter filter)
Append route that supports HTTP PATCH method:
|
Route.Definition |
patch(String path,
Route.Handler handler)
Append route that supports HTTP PATCH method:
|
Route.Definition |
patch(String path,
Route.OneArgHandler handler)
Append route that supports HTTP PATCH method:
|
Route.Definition |
patch(String path,
Route.ZeroArgHandler handler)
Append route that supports HTTP PATCH method:
|
Route.Collection |
patch(String path1,
String path2,
Route.Filter filter)
Append three routes that supports HTTP PATCH method on the same handler:
|
Route.Collection |
patch(String path1,
String path2,
Route.Handler handler)
Append three routes that supports HTTP PATCH method on the same handler:
|
Route.Collection |
patch(String path1,
String path2,
Route.OneArgHandler handler)
Append three routes that supports HTTP PATCH method on the same handler:
|
Route.Collection |
patch(String path1,
String path2,
Route.ZeroArgHandler handler)
Append three routes that supports HTTP PATCH method on the same handler:
|
Route.Collection |
patch(String path1,
String path2,
String path3,
Route.Filter filter)
Append three routes that supports HTTP PATCH method on the same handler:
|
Route.Collection |
patch(String path1,
String path2,
String path3,
Route.Handler handler)
Append three routes that supports HTTP PATCH method on the same handler:
|
Route.Collection |
patch(String path1,
String path2,
String path3,
Route.OneArgHandler handler)
Append three routes that supports HTTP PATCH method on the same handler:
|
Route.Collection |
patch(String path1,
String path2,
String path3,
Route.ZeroArgHandler handler)
Append three routes that supports HTTP PATCH method on the same handler:
|
Route.Definition |
post(String path,
Route.Filter filter)
Append a route that supports HTTP POST method:
|
Route.Definition |
post(String path,
Route.Handler handler)
Append a route that supports HTTP POST method:
|
Route.Definition |
post(String path,
Route.OneArgHandler handler)
Append route that supports HTTP POST method:
|
Route.Definition |
post(String path,
Route.ZeroArgHandler handler)
Append route that supports HTTP POST method:
|
Route.Collection |
post(String path1,
String path2,
Route.Filter filter)
Append three routes that supports HTTP POST method on the same handler:
|
Route.Collection |
post(String path1,
String path2,
Route.Handler handler)
Append three routes that supports HTTP POST method on the same handler:
|
Route.Collection |
post(String path1,
String path2,
Route.OneArgHandler handler)
Append three routes that supports HTTP POST method on the same handler:
|
Route.Collection |
post(String path1,
String path2,
Route.ZeroArgHandler handler)
Append three routes that supports HTTP POST method on the same handler:
|
Route.Collection |
post(String path1,
String path2,
String path3,
Route.Filter filter)
Append three routes that supports HTTP POST method on the same handler:
|
Route.Collection |
post(String path1,
String path2,
String path3,
Route.Handler handler)
Append three routes that supports HTTP POST method on the same handler:
|
Route.Collection |
post(String path1,
String path2,
String path3,
Route.OneArgHandler handler)
Append three routes that supports HTTP POST method on the same handler:
|
Route.Collection |
post(String path1,
String path2,
String path3,
Route.ZeroArgHandler handler)
Append three routes that supports HTTP POST method on the same handler:
|
Route.Definition |
put(String path,
Route.Filter filter)
Append route that supports HTTP PUT method:
|
Route.Definition |
put(String path,
Route.Handler handler)
Append route that supports HTTP PUT method:
|
Route.Definition |
put(String path,
Route.OneArgHandler handler)
Append route that supports HTTP PUT method:
|
Route.Definition |
put(String path,
Route.ZeroArgHandler handler)
Append route that supports HTTP PUT method:
|
Route.Collection |
put(String path1,
String path2,
Route.Filter filter)
Append three routes that supports HTTP PUT method on the same handler:
|
Route.Collection |
put(String path1,
String path2,
Route.Handler handler)
Append three routes that supports HTTP PUT method on the same handler:
|
Route.Collection |
put(String path1,
String path2,
Route.OneArgHandler handler)
Append three routes that supports HTTP PUT method on the same handler:
|
Route.Collection |
put(String path1,
String path2,
Route.ZeroArgHandler handler)
Append three routes that supports HTTP PUT method on the same handler:
|
Route.Collection |
put(String path1,
String path2,
String path3,
Route.Filter filter)
Append three routes that supports HTTP PUT method on the same handler:
|
Route.Collection |
put(String path1,
String path2,
String path3,
Route.Handler handler)
Append three routes that supports HTTP PUT method on the same handler:
|
Route.Collection |
put(String path1,
String path2,
String path3,
Route.OneArgHandler handler)
Append three routes that supports HTTP PUT method on the same handler:
|
Route.Collection |
put(String path1,
String path2,
String path3,
Route.ZeroArgHandler handler)
Append three routes that supports HTTP PUT method on the same handler:
|
Route.Definition |
sse(String path,
Sse.Handler handler)
Add a server-sent event handler.
|
Route.Definition |
sse(String path,
Sse.Handler1 handler)
Add a server-sent event handler.
|
Route.Definition |
trace()
Append a default trace implementation under the given path.
|
Route.Definition |
trace(String path,
Route.Filter filter)
Append a route that supports HTTP TRACE method:
|
Route.Definition |
trace(String path,
Route.Handler handler)
Append a route that supports HTTP TRACE method:
|
Route.Definition |
trace(String path,
Route.OneArgHandler handler)
Append route that supports HTTP TRACE method:
|
Route.Definition |
trace(String path,
Route.ZeroArgHandler handler)
Append route that supports HTTP TRACE method:
|
Route.Collection |
use(Class<?> routeClass)
Append one or more routes defined in the given class.
|
Route.Group |
use(String pattern)
Define one or more routes under the same namespace:
|
Route.Definition |
use(String path,
Route.Filter filter)
Append a new filter that matches any method under the given path.
|
Route.Definition |
use(String path,
Route.Handler handler)
Append a new route handler that matches any method under the given path.
|
Route.Definition |
use(String path,
Route.OneArgHandler handler)
Append a new route handler that matches any method under the given path.
|
Route.Definition |
use(String verb,
String path,
Route.Filter filter)
Append a new filter that matches any method under the given path.
|
Route.Definition |
use(String verb,
String path,
Route.Handler handler)
Append a new route handler that matches any method under the given path.
|
Route.Collection |
with(Runnable callback)
Apply common configuration and attributes to a group of routes:
|
WebSocket.Definition |
ws(String path,
WebSocket.Handler handler)
Append a new WebSocket handler under the given path.
|
Route.Group use(String pattern)
{ use("/pets") .get("/{id}", req -> db.get(req.param("id").value())) .get(() -> db.values()); }
pattern
- Global pattern to use.Route.Definition use(String path, Route.Filter filter)
path
- A path pattern.filter
- A filter to execute.Route.Definition use(String verb, String path, Route.Filter filter)
verb
- A HTTP verb.path
- A path pattern.filter
- A filter to execute.Route.Definition use(String verb, String path, Route.Handler handler)
verb
- A HTTP verb.path
- A path pattern.handler
- A handler to execute.Route.Definition use(String path, Route.Handler handler)
path
- A path pattern.handler
- A handler to execute.Route.Definition use(String path, Route.OneArgHandler handler)
path
- A path pattern.handler
- A handler to execute.Route.Definition get(String path, Route.Handler handler)
get("/", (req, rsp) -> { rsp.send(something); });This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A handler to execute.Route.Collection get(String path1, String path2, Route.Handler handler)
get("/model", "/mode/:id", req -> { return req.param("id").toOptional(String.class); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.handler
- A handler to execute.Route.Collection get(String path1, String path2, String path3, Route.Handler handler)
get("/p1", "/p2", "/p3", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.path3
- A path pattern.handler
- A handler to execute.Route.Definition get(String path, Route.OneArgHandler handler)
get("/", (req) -> "hello" );This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A handler to execute.Route.Collection get(String path1, String path2, Route.OneArgHandler handler)
get("/model", "/model/:id", req -> { return req.param("id").toOptional(String.class); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.handler
- A handler to execute.Route.Collection get(String path1, String path2, String path3, Route.OneArgHandler handler)
get("/p1", "/p2", "/p3", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.path3
- A path pattern.handler
- A handler to execute.Route.Definition get(String path, Route.ZeroArgHandler handler)
get("/", () -> "hello" );This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A handler to execute.Route.Collection get(String path1, String path2, Route.ZeroArgHandler handler)
get("/model", "/model/:id", req -> { return req.param("id").toOptional(String.class); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.handler
- A handler to execute.Route.Collection get(String path1, String path2, String path3, Route.ZeroArgHandler handler)
get("/p1", "/p2", "/p3", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.path3
- A path pattern.handler
- A handler to execute.Route.Definition get(String path, Route.Filter filter)
get("/", (req, rsp, chain) -> { chain.next(req, rsp); });This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.filter
- A filter to execute.Route.Collection get(String path1, String path2, Route.Filter filter)
get("/model", "/model/:id", req -> { return req.param("id").toOptional(String.class); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.filter
- A filter to execute.Route.Collection get(String path1, String path2, String path3, Route.Filter filter)
get("/p1", "/p2", "/p3", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.path3
- A path pattern.filter
- A filter to execute.Route.Definition post(String path, Route.Handler handler)
post("/", (req, rsp) -> { rsp.send(something); });This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A handler to execute.Route.Collection post(String path1, String path2, Route.Handler handler)
post("/p1", "/p2", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.handler
- A handler to execute.Route.Collection post(String path1, String path2, String path3, Route.Handler handler)
post("/p1", "/p2", "/p3", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.path3
- A path pattern.handler
- A handler to execute.Route.Definition post(String path, Route.OneArgHandler handler)
post("/", (req) -> "hello" );This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A handler to execute.Route.Collection post(String path1, String path2, Route.OneArgHandler handler)
post("/p1", "/p2", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.handler
- A handler to execute.Route.Collection post(String path1, String path2, String path3, Route.OneArgHandler handler)
post("/p1", "/p2", "/p3", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.path3
- A path pattern.handler
- A handler to execute.Route.Definition post(String path, Route.ZeroArgHandler handler)
post("/", () -> "hello" );This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A handler to execute.Route.Collection post(String path1, String path2, Route.ZeroArgHandler handler)
post("/p1", "/p2", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.handler
- A handler to execute.Route.Collection post(String path1, String path2, String path3, Route.ZeroArgHandler handler)
post("/p1", "/p2", "/p3", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.path3
- A path pattern.handler
- A handler to execute.Route.Definition post(String path, Route.Filter filter)
post("/", (req, rsp, chain) -> { chain.next(req, rsp); });This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.filter
- A filter to execute.Route.Collection post(String path1, String path2, Route.Filter filter)
post("/p1", "/p2", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.filter
- A filter to execute.Route.Collection post(String path1, String path2, String path3, Route.Filter filter)
post("/p1", "/p2", "/p3", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.path3
- A path pattern.filter
- A filter to execute.Route.Definition head(String path, Route.Handler handler)
post("/", (req, rsp) -> { rsp.send(something); });This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A handler to execute.Route.Definition head(String path, Route.OneArgHandler handler)
head("/", (req) -> "hello" );This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A handler to execute.Route.Definition head(String path, Route.ZeroArgHandler handler)
head("/", () -> "hello" );This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A handler to execute.Route.Definition head(String path, Route.Filter filter)
post("/", (req, rsp, chain) -> { chain.next(req, rsp); });This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.filter
- A filter to execute.Route.Definition head()
get("/", (req, rsp) -> { rsp.send(something); // This route provides default HEAD for this GET route. });
Route.Definition options(String path, Route.Handler handler)
options("/", (req, rsp) -> { rsp.header("Allow", "GET, POST"); });This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A handler to execute.Route.Definition options(String path, Route.OneArgHandler handler)
options("/", (req) -> Body.status(200).header("Allow", "GET, POST") );This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A handler to execute.Route.Definition options(String path, Route.ZeroArgHandler handler)
options("/", () -> Body.status(200).header("Allow", "GET, POST") );This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A handler to execute.Route.Definition options(String path, Route.Filter filter)
options("/", (req, rsp, chain) -> { rsp.header("Allow", "GET, POST"); chain.next(req, rsp); });This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.filter
- A callback to execute.Route.Definition options()
get("/", (req, rsp) -> { rsp.send(something); }); post("/", (req, rsp) -> { rsp.send(something); });OPTINOS / produces a response with a Allow header set to: GET, POST.
Route.Definition put(String path, Route.Handler handler)
put("/", (req, rsp) -> { rsp.send(something); });This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A route to execute.Route.Collection put(String path1, String path2, Route.Handler handler)
put("/p1", "/p2", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.handler
- A handler to execute.Route.Collection put(String path1, String path2, String path3, Route.Handler handler)
put("/p1", "/p2", "/p3", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.path3
- A path pattern.handler
- A handler to execute.Route.Definition put(String path, Route.OneArgHandler handler)
put("/", (req) -> Body.status(202) );This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A handler to execute.Route.Collection put(String path1, String path2, Route.OneArgHandler handler)
put("/p1", "/p2", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.handler
- A handler to execute.Route.Collection put(String path1, String path2, String path3, Route.OneArgHandler handler)
put("/p1", "/p2", "/p3", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.path3
- A path pattern.handler
- A handler to execute.Route.Definition put(String path, Route.ZeroArgHandler handler)
put("/", () -> { Body.status(202) });This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A handler to execute.Route.Collection put(String path1, String path2, Route.ZeroArgHandler handler)
put("/p1", "/p2", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.handler
- A handler to execute.Route.Collection put(String path1, String path2, String path3, Route.ZeroArgHandler handler)
put("/p1", "/p2", "/p3", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.path3
- A path pattern.handler
- A handler to execute.Route.Definition put(String path, Route.Filter filter)
put("/", (req, rsp, chain) -> { chain.next(req, rsp); });This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.filter
- A callback to execute.Route.Collection put(String path1, String path2, Route.Filter filter)
put("/p1", "/p2", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.filter
- A filter to execute.Route.Collection put(String path1, String path2, String path3, Route.Filter filter)
put("/p1", "/p2", "/p3", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.path3
- A path pattern.filter
- A filter to execute.Route.Definition patch(String path, Route.Handler handler)
patch("/", (req, rsp) -> { rsp.send(something); });This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A route to execute.Route.Collection patch(String path1, String path2, Route.Handler handler)
patch("/p1", "/p2", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.handler
- A handler to execute.Route.Collection patch(String path1, String path2, String path3, Route.Handler handler)
patch("/p1", "/p2", "/p3", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.path3
- A path pattern.handler
- A handler to execute.Route.Definition patch(String path, Route.OneArgHandler handler)
patch("/", (req) -> Body.status(202) );This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A handler to execute.Route.Collection patch(String path1, String path2, Route.OneArgHandler handler)
patch("/p1", "/p2", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.handler
- A handler to execute.Route.Collection patch(String path1, String path2, String path3, Route.OneArgHandler handler)
patch("/p1", "/p2", "/p3", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.path3
- A path pattern.handler
- A handler to execute.Route.Definition patch(String path, Route.ZeroArgHandler handler)
patch("/", () -> { Body.status(202) });This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A handler to execute.Route.Collection patch(String path1, String path2, Route.ZeroArgHandler handler)
patch("/p1", "/p2", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.handler
- A handler to execute.Route.Collection patch(String path1, String path2, String path3, Route.ZeroArgHandler handler)
patch("/p1", "/p2", "/p3", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.path3
- A path pattern.handler
- A handler to execute.Route.Definition patch(String path, Route.Filter filter)
patch("/", (req, rsp, chain) -> { chain.next(req, rsp); });This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.filter
- A callback to execute.Route.Collection patch(String path1, String path2, Route.Filter filter)
patch("/p1", "/p2", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.filter
- A filter to execute.Route.Collection patch(String path1, String path2, String path3, Route.Filter filter)
patch("/p1", "/p2", "/p3", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.path3
- A path pattern.filter
- A filter to execute.Route.Definition delete(String path, Route.Handler handler)
delete("/", (req, rsp) -> { rsp.status(304); });This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A handler to execute.Route.Collection delete(String path1, String path2, Route.Handler handler)
delete("/p1", "/p2", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.handler
- A handler to execute.Route.Collection delete(String path1, String path2, String path3, Route.Handler handler)
delete("/p1", "/p2", "/p3", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.path3
- A path pattern.handler
- A handler to execute.Route.Definition delete(String path, Route.OneArgHandler handler)
delete("/", (req) -> Body.status(204) );This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A handler to execute.Route.Collection delete(String path1, String path2, Route.OneArgHandler handler)
delete("/p1", "/p2", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.handler
- A handler to execute.Route.Collection delete(String path1, String path2, String path3, Route.OneArgHandler handler)
delete("/p1", "/p2", "/p3", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.path3
- A path pattern.handler
- A handler to execute.Route.Definition delete(String path, Route.ZeroArgHandler handler)
delete("/", () -> Body.status(204) );This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A handler to execute.Route.Collection delete(String path1, String path2, Route.ZeroArgHandler handler)
delete("/p1", "/p2", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.handler
- A handler to execute.Route.Collection delete(String path1, String path2, String path3, Route.ZeroArgHandler handler)
delete("/p1", "/p2", "/p3", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.path3
- A path pattern.handler
- A handler to execute.Route.Definition delete(String path, Route.Filter filter)
delete("/", (req, rsp, chain) -> { rsp.status(304); chain.next(req, rsp); });This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.filter
- A callback to execute.Route.Collection delete(String path1, String path2, Route.Filter filter)
delete("/p1", "/p2", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.filter
- A filter to execute.Route.Collection delete(String path1, String path2, String path3, Route.Filter filter)
delete("/p1", "/p2", "/p3", req -> { return req.path(); });This is a singleton route so make sure you don't share or use global variables.
path1
- A path pattern.path2
- A path pattern.path3
- A path pattern.filter
- A filter to execute.Route.Definition trace(String path, Route.Handler handler)
trace("/", (req, rsp) -> { rsp.send(...); });This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A callback to execute.Route.Definition trace(String path, Route.OneArgHandler handler)
trace("/", (req) -> "trace" );This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A handler to execute.Route.Definition trace(String path, Route.ZeroArgHandler handler)
trace("/", () -> "trace" );This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A handler to execute.Route.Definition trace(String path, Route.Filter filter)
trace("/", (req, rsp, chain) -> { chain.next(req, rsp); });This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.filter
- A callback to execute.Route.Definition trace()
TRACE /path header1: value header2: value
Route.Definition connect(String path, Route.Handler handler)
connect("/", (req, rsp, chain) -> { chain.next(req, rsp); });This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A handler to execute.Route.Definition connect(String path, Route.OneArgHandler handler)
connect("/", (req) -> "hello" );This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A handler to execute.Route.Definition connect(String path, Route.ZeroArgHandler handler)
connect("/", () -> "connected" );This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.handler
- A handler to execute.Route.Definition connect(String path, Route.Filter filter)
connect("/", (req, rsp, chain) -> { chain.next(req, rsp); });This is a singleton route so make sure you don't share or use global variables.
path
- A path pattern.filter
- A filter to execute.Route.Definition assets(String path)
assets("/assets/**");Resources are served from root of classpath, for example
GET /assets/file.js
will
be resolve as classpath resource at the same location.path
- The path to publish.Route.Definition assets(String path, String location)
Basic example
assets("/js/**", "/");A request for:
/js/jquery.js
will be translated to: /lib/jquery.js
.
Webjars example:
assets("/js/**", "/resources/webjars/{0}");A request for:
/js/jquery/2.1.3/jquery.js
will be translated to:
/resources/webjars/jquery/2.1.3/jquery.js
.
The {0}
represent the **
capturing group.
Another webjars example:
assets("/js/*-*.js", "/resources/webjars/{0}/{1}/{0}.js");
A request for: /js/jquery-2.1.3.js
will be translated to:
/resources/webjars/jquery/2.1.3/jquery.js
.
path
- The path to publish.location
- A resource location.Route.Definition assets(String path, AssetHandler handler)
Basic example
assets("/js/**", "/");A request for:
/js/jquery.js
will be translated to: /lib/jquery.js
.
Webjars example:
assets("/js/**", "/resources/webjars/{0}");A request for:
/js/jquery/2.1.3/jquery.js
will be translated to:
/resources/webjars/jquery/2.1.3/jquery.js
.
The {0}
represent the **
capturing group.
Another webjars example:
assets("/js/*-*.js", "/resources/webjars/{0}/{1}/{0}.js");
A request for: /js/jquery-2.1.3.js
will be translated to:
/resources/webjars/jquery/2.1.3/jquery.js
.
path
- The path to publish.handler
- Asset handler.Route.Collection use(Class<?> routeClass)
Append one or more routes defined in the given class.
use(MyRoute.class); ... // MyRoute.java @Path("/") public class MyRoute { @GET public String hello() { return "Hello Jooby"; } }
Programming model is quite similar to JAX-RS/Jersey with some minor differences and/or simplifications.
To learn more about Mvc Routes, please check Path
,
Produces
Consumes
.
routeClass
- A route(s) class.default Route.Collection before(Route.Before handler, Route.Before... chain)
{
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.
handler
- Before handler.chain
- Chain of before handler.default Route.Collection before(String pattern, Route.Before handler, Route.Before... chain)
{
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);
chain.next(req, rsp);
});
}
A before
handler must to be registered before the actual handler you want to
intercept.
{
before("/path", (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.
pattern
- Pattern to intercept.handler
- Before handler.chain
- Chain of before handler.Route.Collection before(String method, String pattern, Route.Before handler, Route.Before... chain)
{
before("GET", "*", (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("GET", "*", (req, rsp, chain) -> {
before(req, rsp);
chain.next(req, rsp);
});
}
A before
handler must to be registered before the actual handler you want to
intercept.
{
before("GET", "/path", (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.
method
- HTTP method to intercept.pattern
- Pattern to intercept.handler
- Before handler.chain
- Chain of before handler.default Route.Collection after(Route.After handler, Route.After... chain)
{
after((req, rsp, result) -> {
// your code goes here
return result;
});
}
You are allowed to modify the request, response and result objects. The handler returns a
Result
which can be the same or an entirely new Result
.
Please note that the after
handler is just syntax sugar for
Route.Filter
.
For example, the after
handler was implemented as:
{
use("*", (req, rsp, chain) -> {
chain.next(req, new Response.Forwarding(rsp) {
public void send(Result result) {
rsp.send(after(req, rsp, result);
}
});
});
}
Due after
is implemented by wrapping the Response
object. A
after
handler must to be registered before the actual handler you want to
intercept.
{
after((req, rsp, result) -> {
// your code goes here
return result;
});
get("/path", req -> {
return "hello";
});
}
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.
handler
- After handler.chain
- After chain.default Route.Collection after(String pattern, Route.After handler, Route.After... chain)
{
before("*", (req, rsp, result) -> {
// your code goes here
return result;
});
}
You are allowed to modify the request, response and result objects. The handler returns a
Result
which can be the same or an entirely new Result
.
Please note that the after
handler is just syntax sugar for Route.Filter
.
For example, the after
handler was implemented as:
{
use("*", (req, rsp, chain) -> {
chain.next(req, new Response.Forwarding(rsp) {
public void send(Result result) {
rsp.send(after(req, rsp, result);
}
});
});
}
Due after
is implemented by wrapping the Response
object. A
after
handler must to be registered before the actual handler you want to
intercept.
{
after("/path", (req, rsp, result) -> {
// your code goes here
return result;
});
get("/path", req -> {
return "hello";
});
}
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.
pattern
- Pattern to intercept.handler
- After handler.chain
- After chain.Route.Collection after(String method, String pattern, Route.After handler, Route.After... chain)
{
after("GET", "*", (req, rsp, result) -> {
// your code goes here
return result;
});
}
You are allowed to modify the request, response and result objects. The handler returns a
Result
which can be the same or an entirely new Result
.
Please note that the after
handler is just syntax sugar for
Route.Filter
.
For example, the after
handler was implemented as:
{
use("GET", "*", (req, rsp, chain) -> {
chain.next(req, new Response.Forwarding(rsp) {
public void send(Result result) {
rsp.send(after(req, rsp, result);
}
});
});
}
Due after
is implemented by wrapping the Response
object. A
after
handler must to be registered before the actual handler you want to
intercept.
{
after("GET", "/path", (req, rsp, result) -> {
// your code goes here
return result;
});
get("/path", req -> {
return "hello";
});
}
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.
method
- HTTP method to intercept.pattern
- Pattern to intercept.handler
- After handler.chain
- After chain.default Route.Collection complete(Route.Complete handler, Route.Complete... chain)
{
complete((req, rsp, cause) -> {
// your code goes here
});
}
You are NOT allowed to modify the request and response objects. The cause
is an
Optional
with a Throwable
useful to identify problems.
The goal of the after
handler is to probably cleanup request object and log
responses.
Please note that the complete
handler is just syntax sugar for
Route.Filter
.
For example, the complete
handler was implemented as:
{
use("*", "*", (req, rsp, chain) -> {
Optional<Throwable> err = Optional.empty();
try {
chain.next(req, rsp);
} catch (Throwable cause) {
err = Optional.of(cause);
} finally {
complete(req, rsp, err);
}
});
}
An complete
handler must to be registered before the actual handler you want to
intercept.
{
complete((req, rsp, cause) -> {
// your code goes here
});
get(req -> {
return "hello";
});
}
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.
Suppose you have a transactional resource, like a database connection. The next example shows
you how to implement a simple and effective transaction-per-request
pattern:
{
// start transaction
before((req, rsp) -> {
DataSource ds = req.require(DataSource.class);
Connection connection = ds.getConnection();
Transaction trx = connection.getTransaction();
trx.begin();
req.set("connection", connection);
return true;
});
// commit/rollback transaction
complete((req, rsp, cause) -> {
// unbind connection from request
try(Connection connection = req.unset("connection").get()) {
Transaction trx = connection.getTransaction();
if (cause.ifPresent()) {
trx.rollback();
} else {
trx.commit();
}
}
});
// your transactional routes goes here
get("/api/something", req -> {
Connection connection = req.get("connection");
// work with connection
});
}
handler
- Complete handler.chain
- Complete chain.default Route.Collection complete(String pattern, Route.Complete handler, Route.Complete... chain)
{
complete("*", (req, rsp, cause) -> {
// your code goes here
});
}
You are NOT allowed to modify the request and response objects. The cause
is an
Optional
with a Throwable
useful to identify problems.
The goal of the complete
handler is to probably cleanup request object and log
responses.
Please note that the complete
handler is just syntax sugar for
Route.Filter
.
For example, the complete
handler was implemented as:
{
use("*", "*", (req, rsp, chain) -> {
Optional<Throwable> err = Optional.empty();
try {
chain.next(req, rsp);
} catch (Throwable cause) {
err = Optional.of(cause);
} finally {
complete(req, rsp, err);
}
});
}
An complete
handler must to be registered before the actual handler you want to
intercept.
{
complete("/path", (req, rsp, cause) -> {
// your code goes here
});
get("/path", req -> {
return "hello";
});
}
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.
Suppose you have a transactional resource, like a database connection. The next example shows
you how to implement a simple and effective transaction-per-request
pattern:
{
// start transaction
before("/api/*", (req, rsp) -> {
DataSource ds = req.require(DataSource.class);
Connection connection = ds.getConnection();
Transaction trx = connection.getTransaction();
trx.begin();
req.set("connection", connection);
return true;
});
// commit/rollback transaction
complete("/api/*", (req, rsp, cause) -> {
// unbind connection from request
try(Connection connection = req.unset("connection").get()) {
Transaction trx = connection.getTransaction();
if (cause.ifPresent()) {
trx.rollback();
} else {
trx.commit();
}
}
});
// your transactional routes goes here
get("/api/something", req -> {
Connection connection = req.get("connection");
// work with connection
});
}
pattern
- Pattern to intercept.handler
- Complete handler.chain
- Complete chain.Route.Collection complete(String method, String pattern, Route.Complete handler, Route.Complete... chain)
{
complete("*", "*", (req, rsp, cause) -> {
// your code goes here
});
}
You are NOT allowed to modify the request and response objects. The cause
is an
Optional
with a Throwable
useful to identify problems.
The goal of the complete
handler is to probably cleanup request object and log
responses.
Please note that the complete
handler is just syntax sugar for
Route.Filter
.
For example, the complete
handler was implemented as:
{
use("*", "*", (req, rsp, chain) -> {
Optional<Throwable> err = Optional.empty();
try {
chain.next(req, rsp);
} catch (Throwable cause) {
err = Optional.of(cause);
} finally {
complete(req, rsp, err);
}
});
}
An complete
handler must to be registered before the actual handler you want to
intercept.
{
complete("*", "/path", (req, rsp, cause) -> {
});
get("/path", req -> {
return "hello";
});
}
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.
Suppose you have a transactional resource, like a database connection. The next example shows
you how to implement a simple and effective transaction-per-request
pattern:
{
// start transaction
before((req, rsp) -> {
DataSource ds = req.require(DataSource.class);
Connection connection = ds.getConnection();
Transaction trx = connection.getTransaction();
trx.begin();
req.set("connection", connection);
return true;
});
// commit/rollback transaction
complete((req, rsp, cause) -> {
// unbind connection from request
try(Connection connection = req.unset("connection")) {
Transaction trx = connection.getTransaction();
if (cause.ifPresent()) {
trx.rollback();
} else {
trx.commit();
}
}
});
// your transactional routes goes here
get("/my-trx-route", req -> {
Connection connection = req.get("connection");
// work with connection
});
}
method
- HTTP method to intercept.pattern
- Pattern to intercept.handler
- Complete handler.chain
- Complete chain.WebSocket.Definition ws(String path, WebSocket.Handler handler)
ws("/ws", (socket) -> { // connected socket.onMessage(message -> { System.out.println(message); }); socket.send("Connected"): });
path
- A path pattern.handler
- A connect callback.Route.Definition sse(String path, Sse.Handler handler)
{
sse("/path",(req, sse) -> {
// 1. connected
sse.send("data"); // 2. send/push data
});
}
path
- Event path.handler
- Callback. It might executed in a different thread (web server choice).Route.Definition sse(String path, Sse.Handler1 handler)
{
sse("/path", sse -> {
// 1. connected
sse.send("data"); // 2. send/push data
});
}
path
- Event path.handler
- Callback. It might executed in a different thread (web server choice).Route.Collection with(Runnable callback)
{
with(() -> {
get("/foo", ...);
get("/bar", ...);
get("/etc", ...);
...
}).attr("v1", "k1")
.excludes("/public/**");
}
All the routes wrapped by with
will have a v1
attribute and will
excludes/ignores a /public
request.callback
- Route callback.Routes map(Route.Mapper<?> mapper)
{
mapper((Integer v) -> v * 2);
mapper(v -> Integer.parseInt(v.toString()));
get("/four", () -> "2");
}
A call to /four
outputs 4
.mapper
- Route mapper to append.Routes err(Err.Handler err)
Err.DefHandler
does content
negotation and this method allow to override/complement default handler.err
- A route error handler.default Routes err(Class<? extends Throwable> type, Err.Handler handler)
type
- Exception type. The error handler will be executed if the current exception is an
instance of this type.handler
- A route error handler.default Routes err(int statusCode, Err.Handler handler)
statusCode
- The status code to match.handler
- A route error handler.Copyright © 2016. All rights reserved.