public interface ResultHandler
Bind a route response type to a custom handler. The response handler works like a map function,
which applies to a specific response type.
For example if your route produces a Foo
type as response. You can write a
FooHandler that knows how to render the Foo
object.
Mapping is done efficiently, it doesn't test every single route response at runtime. Instead
analysis is done only once at application startup time, it generates a unique route pipeline for
all the routes that generates a Foo
output.
Example:
{
boolean matches(Type type) {
return Foo.class == type;
}
Route.Filter create() {
return next -> ctx -> {
Foo foo = (Foo) next.apply(ctx);
return ctx.sendString(foo.toString());
}
}
}
- Since:
- 2.0.0
- Author:
- edgar
-
Method Summary
Modifier and TypeMethodDescriptioncreate()
Creates a handler for a response type.boolean
boolean
True if response route type is the one expected by the response handler.
-
Method Details
-
matches
True if response route type is the one expected by the response handler.- Parameters:
type
- Type to test.- Returns:
- True if response route type is the one expected by the response handler.
-
isReactive
boolean isReactive() -
create
Creates a handler for a response type. Example:{ boolean matches(Type type) { return Foo.class == type; } Route.Filter create() { return next -> ctx -> { Foo foo = (Foo) next.apply(ctx); return ctx.sendString(foo.toString()); } } }
- Returns:
- A response handler.
-