T
- Type to map.public static interface Route.Mapper<T>
{
// we got bar.. not foo
get("/foo", () -> "foo")
.map(value -> "bar");
// we got foo.. not bar
get("/bar", () -> "bar")
.map(value -> "foo");
}
If you want to apply a single map to several routes:
{
with(() -> {
get("/foo", () -> "foo");
get("/bar", () -> "bar");
}).map(v -> "foo or bar");
}
You can apply a Route.Mapper
to specific return type:
{
with(() -> {
get("/str", () -> "str");
get("/int", () -> 1);
}).map(String v -> "{" + v + "}");
}
A call to /str
produces {str}
, while /int
just
1
.
NOTE: You can apply the map operator to routes that produces an output.
For example, the map operator will be silently ignored here:
{
get("/", (req, rsp) -> {
rsp.send(...);
}).map(v -> ..);
}
Modifier and Type | Method and Description |
---|---|
Object |
map(T value)
Map the type to something else.
|
Copyright © 2016. All rights reserved.