T
- The return type of the handler@FunctionalInterface public interface AsyncHandler<T>
Response
value when you want to do things like modify response
headers based on results of service invocations or if you want to set the status code. Example:
public CompletionStage> invoke(RequestContext requestContest) {
return futureToStringPayload().thenApply(
s -> Response.forPayload(s)
.withHeader("X-Payload-Length", s.length()));
}
In order to construct a Route
that can be registered with
Environment.RoutingEngine.registerRoute(Route)
, the return type of the handler must be a
Response<ByteString>
. This return type can be composed through your serialization
functions using map(Function)
and flatMap(Function)
.Modifier and Type | Method and Description |
---|---|
default <V> AsyncHandler<V> |
flatMap(Function<? super T,? extends AsyncHandler<? extends V>> mapFunction)
Create a new
AsyncHandler that will map the return value of
invoke(RequestContext) through the given map function. |
default <V> AsyncHandler<V> |
flatMapSync(Function<? super T,? extends SyncHandler<? extends V>> mapFunction)
Synchronous version of
flatMap(Function) . |
CompletionStage<T> |
invoke(RequestContext requestContext) |
default <V> AsyncHandler<V> |
map(Function<? super T,? extends V> mapFunction)
Create a new
AsyncHandler that will map the return value of
invoke(RequestContext) through the given map function. |
CompletionStage<T> invoke(RequestContext requestContext)
default <V> AsyncHandler<V> map(Function<? super T,? extends V> mapFunction)
AsyncHandler
that will map the return value of
invoke(RequestContext)
through the given map function.V
- The resulting handler typemapFunction
- The mapping functionAsyncHandler
with a composed invoke methoddefault <V> AsyncHandler<V> flatMap(Function<? super T,? extends AsyncHandler<? extends V>> mapFunction)
AsyncHandler
that will map the return value of
invoke(RequestContext)
through the given map function.
The returned AsyncHandler
of the map function will execute with
the same RequestContext
as the current handler.V
- The resulting handler typemapFunction
- The mapping functionAsyncHandler
with a composed invoke methoddefault <V> AsyncHandler<V> flatMapSync(Function<? super T,? extends SyncHandler<? extends V>> mapFunction)
flatMap(Function)
. Use this when you want to do
synchronous maps of the handler return value.V
- The resulting handler typemapFunction
- The mapping functionAsyncHandler
with a composed invoke methodCopyright © 2016. All rights reserved.