public interface ResponseHandler
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.Handler create(Route.Handler next) {
return ctx -> {
Foo foo = (Foo) next.apply(ctx);
return ctx.sendString(foo.toString());
}
}
}
Modifier and Type | Method and Description |
---|---|
Route.Handler |
create(Route.Handler next)
Creates a handler for a response type.
|
boolean |
matches(Type type)
True if response route type is the one expected by the response handler.
|
boolean matches(@Nonnull Type type)
type
- Type to test.@Nonnull Route.Handler create(Route.Handler next)
{
boolean matches(Type type) {
return Foo.class == type;
}
Route.Handler create(Route.Handler next) {
return ctx -> {
Foo foo = (Foo) next.apply(ctx);
return ctx.sendString(foo.toString());
}
}
}
next
- Next route in pipeline (usually the route handler).Copyright © 2020. All rights reserved.