Interface Middleware<I,O>
- Type Parameters:
I- The input typeO- The output type
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Middleware is a function that wraps action execution, allowing pre-processing
and post-processing of requests and responses.
Middleware functions receive the request, action context, and a "next" function to call the next middleware in the chain (or the actual action if at the end of the chain).
Example usage:
Middleware<String, String> loggingMiddleware = (request, context, next) -> {
System.out.println("Before: " + request);
String result = next.apply(request, context);
System.out.println("After: " + result);
return result;
};
-
Method Summary
Modifier and TypeMethodDescriptionhandle(I request, ActionContext context, MiddlewareNext<I, O> next) Processes the request through this middleware.
-
Method Details
-
handle
Processes the request through this middleware.- Parameters:
request- the input requestcontext- the action contextnext- the next function in the middleware chain- Returns:
- the output response
- Throws:
GenkitException- if processing fails
-