Interface RouterFunctions.Builder
- Enclosing class:
- RouterFunctions
RouterFunctions.route().- 
Method SummaryModifier and TypeMethodDescriptionadd(RouterFunction<ServerResponse> routerFunction) Adds the given route to this builder.after(BiFunction<ServerRequest, ServerResponse, ServerResponse> responseProcessor) Filter the response object for all routes created by this builder with the given response processing function.before(Function<ServerRequest, ServerRequest> requestProcessor) Filter the request object for all routes created by this builder with the given request processing function.build()Builds theRouterFunction.DELETE(String pattern, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPDELETErequests that match the given pattern.DELETE(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPDELETErequests that match the given pattern and predicate.DELETE(HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles HTTPDELETErequests.DELETE(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPDELETErequests that match the given predicate.filter(HandlerFilterFunction<ServerResponse, ServerResponse> filterFunction) Filters all routes created by this builder with the given filter function.GET(String pattern, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPGETrequests that match the given pattern.GET(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPGETrequests that match the given pattern and predicate.GET(HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles HTTPGETrequests.GET(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPGETrequests that match the given predicate.HEAD(String pattern, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPHEADrequests that match the given pattern.HEAD(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPHEADrequests that match the given pattern and predicate.HEAD(HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles HTTPHEADrequests.HEAD(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPHEADrequests that match the given predicate.nest(RequestPredicate predicate, Consumer<RouterFunctions.Builder> builderConsumer) Route to a built router function if the given request predicate applies.nest(RequestPredicate predicate, Supplier<RouterFunction<ServerResponse>> routerFunctionSupplier) Route to the supplied router function if the given request predicate applies.onError(Class<? extends Throwable> exceptionType, BiFunction<Throwable, ServerRequest, ServerResponse> responseProvider) Filters all exceptions of the given type by applying the given response provider function.onError(Predicate<Throwable> predicate, BiFunction<Throwable, ServerRequest, ServerResponse> responseProvider) Filters all exceptions that match the predicate by applying the given response provider function.OPTIONS(String pattern, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPOPTIONSrequests that match the given pattern.OPTIONS(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPOPTIONSrequests that match the given pattern and predicate.OPTIONS(HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles HTTPOPTIONSrequests.OPTIONS(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPOPTIONSrequests that match the given predicate.PATCH(String pattern, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPPATCHrequests that match the given pattern.PATCH(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPPATCHrequests that match the given pattern and predicate.PATCH(HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles HTTPPATCHrequests.PATCH(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPPATCHrequests that match the given predicate.path(String pattern, Consumer<RouterFunctions.Builder> builderConsumer) Route to a built router function if the given path prefix pattern applies.path(String pattern, Supplier<RouterFunction<ServerResponse>> routerFunctionSupplier) Route to the supplied router function if the given path prefix pattern applies.POST(String pattern, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPPOSTrequests that match the given pattern.POST(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPPOSTrequests that match the given pattern and predicate.POST(HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles HTTPPOSTrequests.POST(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPPOSTrequests that match the given predicate.PUT(String pattern, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPPUTrequests that match the given pattern.PUT(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPPUTrequests that match the given pattern and predicate.PUT(HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles HTTPPUTrequests.PUT(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPPUTrequests that match the given predicate.Route requests that match the given pattern to resources relative to the given root location.resources(String pattern, Resource location, BiConsumer<Resource, HttpHeaders> headersConsumer) Route requests that match the given pattern to resources relative to the given root location.resources(Function<ServerRequest, Optional<Resource>> lookupFunction) Route to resources using the provided lookup function.resources(Function<ServerRequest, Optional<Resource>> lookupFunction, BiConsumer<Resource, HttpHeaders> headersConsumer) Route to resources using the provided lookup function.route(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all requests that match the given predicate.withAttribute(String name, Object value) Add an attribute with the given name and value to the last route built with this builder.withAttributes(Consumer<Map<String, Object>> attributesConsumer) Manipulate the attributes of the last route built with the given consumer.
- 
Method Details- 
GETAdds a route to the given handler function that handles HTTPGETrequests.- Parameters:
- handlerFunction- the handler function to handle all- GETrequests
- Returns:
- this builder
- Since:
- 5.3
 
- 
GETAdds a route to the given handler function that handles all HTTPGETrequests that match the given pattern.- Parameters:
- pattern- the pattern to match to
- handlerFunction- the handler function to handle all- GETrequests that match- pattern
- Returns:
- this builder
 
- 
GETRouterFunctions.Builder GET(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPGETrequests that match the given predicate.- Parameters:
- predicate- predicate to match
- handlerFunction- the handler function to handle all- GETrequests that match- predicate
- Returns:
- this builder
- Since:
- 5.3
- See Also:
 
- 
GETRouterFunctions.Builder GET(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPGETrequests that match the given pattern and predicate.For instance, the following example routes GET requests for "/user" that accept JSON to the listUsersmethod inuserController:RouterFunction<ServerResponse> route = RouterFunctions.route() .GET("/user", RequestPredicates.accept(MediaType.APPLICATION_JSON), userController::listUsers) .build();- Parameters:
- pattern- the pattern to match to
- predicate- additional predicate to match
- handlerFunction- the handler function to handle all- GETrequests that match- patternand the predicate
- Returns:
- this builder
- See Also:
 
- 
HEADAdds a route to the given handler function that handles HTTPHEADrequests.- Parameters:
- handlerFunction- the handler function to handle all- HEADrequests
- Returns:
- this builder
- Since:
- 5.3
 
- 
HEADAdds a route to the given handler function that handles all HTTPHEADrequests that match the given pattern.- Parameters:
- pattern- the pattern to match to
- handlerFunction- the handler function to handle all- HEADrequests that match- pattern
- Returns:
- this builder
 
- 
HEADRouterFunctions.Builder HEAD(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPHEADrequests that match the given predicate.- Parameters:
- predicate- predicate to match
- handlerFunction- the handler function to handle all- HEADrequests that match- predicate
- Returns:
- this builder
- Since:
- 5.3
- See Also:
 
- 
HEADRouterFunctions.Builder HEAD(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPHEADrequests that match the given pattern and predicate.- Parameters:
- pattern- the pattern to match to
- predicate- additional predicate to match
- handlerFunction- the handler function to handle all- HEADrequests that match- pattern
- Returns:
- this builder
 
- 
POSTAdds a route to the given handler function that handles HTTPPOSTrequests.- Parameters:
- handlerFunction- the handler function to handle all- POSTrequests
- Returns:
- this builder
- Since:
- 5.3
 
- 
POSTAdds a route to the given handler function that handles all HTTPPOSTrequests that match the given pattern.- Parameters:
- pattern- the pattern to match to
- handlerFunction- the handler function to handle all- POSTrequests that match- pattern
- Returns:
- this builder
 
- 
POSTRouterFunctions.Builder POST(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPPOSTrequests that match the given predicate.- Parameters:
- predicate- predicate to match
- handlerFunction- the handler function to handle all- POSTrequests that match- predicate
- Returns:
- this builder
- Since:
- 5.3
- See Also:
 
- 
POSTRouterFunctions.Builder POST(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPPOSTrequests that match the given pattern and predicate.For instance, the following example routes POST requests for "/user" that contain JSON to the addUsermethod inuserController:RouterFunction<ServerResponse> route = RouterFunctions.route() .POST("/user", RequestPredicates.contentType(MediaType.APPLICATION_JSON), userController::addUser) .build();- Parameters:
- pattern- the pattern to match to
- predicate- additional predicate to match
- handlerFunction- the handler function to handle all- POSTrequests that match- pattern
- Returns:
- this builder
 
- 
PUTAdds a route to the given handler function that handles HTTPPUTrequests.- Parameters:
- handlerFunction- the handler function to handle all- PUTrequests
- Returns:
- this builder
- Since:
- 5.3
 
- 
PUTAdds a route to the given handler function that handles all HTTPPUTrequests that match the given pattern.- Parameters:
- pattern- the pattern to match to
- handlerFunction- the handler function to handle all- PUTrequests that match- pattern
- Returns:
- this builder
 
- 
PUTRouterFunctions.Builder PUT(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPPUTrequests that match the given predicate.- Parameters:
- predicate- predicate to match
- handlerFunction- the handler function to handle all- PUTrequests that match- predicate
- Returns:
- this builder
- Since:
- 5.3
- See Also:
 
- 
PUTRouterFunctions.Builder PUT(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPPUTrequests that match the given pattern and predicate.For instance, the following example routes PUT requests for "/user" that contain JSON to the editUsermethod inuserController:RouterFunction<ServerResponse> route = RouterFunctions.route() .PUT("/user", RequestPredicates.contentType(MediaType.APPLICATION_JSON), userController::editUser) .build();- Parameters:
- pattern- the pattern to match to
- predicate- additional predicate to match
- handlerFunction- the handler function to handle all- PUTrequests that match- pattern
- Returns:
- this builder
 
- 
PATCHAdds a route to the given handler function that handles HTTPPATCHrequests.- Parameters:
- handlerFunction- the handler function to handle all- PATCHrequests
- Returns:
- this builder
- Since:
- 5.3
 
- 
PATCHAdds a route to the given handler function that handles all HTTPPATCHrequests that match the given pattern.- Parameters:
- pattern- the pattern to match to
- handlerFunction- the handler function to handle all- PATCHrequests that match- pattern
- Returns:
- this builder
 
- 
PATCHRouterFunctions.Builder PATCH(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPPATCHrequests that match the given predicate.- Parameters:
- predicate- predicate to match
- handlerFunction- the handler function to handle all- PATCHrequests that match- predicate
- Returns:
- this builder
- Since:
- 5.3
- See Also:
 
- 
PATCHRouterFunctions.Builder PATCH(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPPATCHrequests that match the given pattern and predicate.For instance, the following example routes PATCH requests for "/user" that contain JSON to the editUsermethod inuserController:RouterFunction<ServerResponse> route = RouterFunctions.route() .PATCH("/user", RequestPredicates.contentType(MediaType.APPLICATION_JSON), userController::editUser) .build();- Parameters:
- pattern- the pattern to match to
- predicate- additional predicate to match
- handlerFunction- the handler function to handle all- PATCHrequests that match- pattern
- Returns:
- this builder
 
- 
DELETEAdds a route to the given handler function that handles HTTPDELETErequests.- Parameters:
- handlerFunction- the handler function to handle all- DELETErequests
- Returns:
- this builder
- Since:
- 5.3
 
- 
DELETEAdds a route to the given handler function that handles all HTTPDELETErequests that match the given pattern.- Parameters:
- pattern- the pattern to match to
- handlerFunction- the handler function to handle all- DELETErequests that match- pattern
- Returns:
- this builder
 
- 
DELETERouterFunctions.Builder DELETE(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPDELETErequests that match the given predicate.- Parameters:
- predicate- predicate to match
- handlerFunction- the handler function to handle all- DELETErequests that match- predicate
- Returns:
- this builder
- Since:
- 5.3
- See Also:
 
- 
DELETERouterFunctions.Builder DELETE(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPDELETErequests that match the given pattern and predicate.- Parameters:
- pattern- the pattern to match to
- predicate- additional predicate to match
- handlerFunction- the handler function to handle all- DELETErequests that match- pattern
- Returns:
- this builder
 
- 
OPTIONSAdds a route to the given handler function that handles HTTPOPTIONSrequests.- Parameters:
- handlerFunction- the handler function to handle all- OPTIONSrequests
- Returns:
- this builder
- Since:
- 5.3
 
- 
OPTIONSAdds a route to the given handler function that handles all HTTPOPTIONSrequests that match the given pattern.- Parameters:
- pattern- the pattern to match to
- handlerFunction- the handler function to handle all- OPTIONSrequests that match- pattern
- Returns:
- this builder
 
- 
OPTIONSRouterFunctions.Builder OPTIONS(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPOPTIONSrequests that match the given predicate.- Parameters:
- predicate- predicate to match
- handlerFunction- the handler function to handle all- OPTIONSrequests that match- predicate
- Returns:
- this builder
- Since:
- 5.3
- See Also:
 
- 
OPTIONSRouterFunctions.Builder OPTIONS(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPOPTIONSrequests that match the given pattern and predicate.- Parameters:
- pattern- the pattern to match to
- predicate- additional predicate to match
- handlerFunction- the handler function to handle all- OPTIONSrequests that match- pattern
- Returns:
- this builder
 
- 
routeRouterFunctions.Builder route(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all requests that match the given predicate.- Parameters:
- predicate- the request predicate to match
- handlerFunction- the handler function to handle all requests that match the predicate
- Returns:
- this builder
- See Also:
 
- 
addAdds the given route to this builder. Can be used to merge externally defined router functions into this builder, or can be combined withRouterFunctions.route(RequestPredicate, HandlerFunction)to allow for more flexible predicate matching.For instance, the following example adds the router function returned from OrderController.routerFunction(). to thechangeUsermethod inuserController:RouterFunction<ServerResponse> route = RouterFunctions.route() .GET("/users", userController::listUsers) .add(orderController.routerFunction()); .build();- Parameters:
- routerFunction- the router function to be added
- Returns:
- this builder
- See Also:
 
- 
resourcesRoute requests that match the given pattern to resources relative to the given root location. For instanceResource location = new FileSystemResource("public-resources/"); RouterFunction<ServerResponse> resources = RouterFunctions.resources("/resources/**", location);- Parameters:
- pattern- the pattern to match
- location- the location directory relative to which resources should be resolved
- Returns:
- this builder
 
- 
resourcesRouterFunctions.Builder resources(String pattern, Resource location, BiConsumer<Resource, HttpHeaders> headersConsumer) Route requests that match the given pattern to resources relative to the given root location. For instanceResource location = new FileSystemResource("public-resources/"); RouterFunction<ServerResponse> resources = RouterFunctions.resources("/resources/**", location);- Parameters:
- pattern- the pattern to match
- location- the location directory relative to which resources should be resolved
- headersConsumer- provides access to the HTTP headers for served resources
- Returns:
- this builder
- Since:
- 6.1
 
- 
resourcesRoute to resources using the provided lookup function. If the lookup function provides aResourcefor the given request, it will be it will be exposed using aHandlerFunctionthat handles GET, HEAD, and OPTIONS requests.- Parameters:
- lookupFunction- the function to provide a- Resourcegiven the- ServerRequest
- Returns:
- this builder
 
- 
resourcesRouterFunctions.Builder resources(Function<ServerRequest, Optional<Resource>> lookupFunction, BiConsumer<Resource, HttpHeaders> headersConsumer) Route to resources using the provided lookup function. If the lookup function provides aResourcefor the given request, it will be it will be exposed using aHandlerFunctionthat handles GET, HEAD, and OPTIONS requests.- Parameters:
- lookupFunction- the function to provide a- Resourcegiven the- ServerRequest
- headersConsumer- provides access to the HTTP headers for served resources
- Returns:
- this builder
- Since:
- 6.1
 
- 
nestRouterFunctions.Builder nest(RequestPredicate predicate, Supplier<RouterFunction<ServerResponse>> routerFunctionSupplier) Route to the supplied router function if the given request predicate applies. This method can be used to create nested routes, where a group of routes share a common path (prefix), header, or other request predicate.For instance, the following example creates a nested route with a "/user" path predicate, so that GET requests for "/user" will list users, and POST request for "/user" will create a new user. RouterFunction<ServerResponse> nestedRoute = RouterFunctions.route() .nest(RequestPredicates.path("/user"), () -> RouterFunctions.route() .GET(this::listUsers) .POST(this::createUser) .build()) .build();- Parameters:
- predicate- the predicate to test
- routerFunctionSupplier- supplier for the nested router function to delegate to if the predicate applies
- Returns:
- this builder
- See Also:
 
- 
nestRouterFunctions.Builder nest(RequestPredicate predicate, Consumer<RouterFunctions.Builder> builderConsumer) Route to a built router function if the given request predicate applies. This method can be used to create nested routes, where a group of routes share a common path (prefix), header, or other request predicate.For instance, the following example creates a nested route with a "/user" path predicate, so that GET requests for "/user" will list users, and POST request for "/user" will create a new user. RouterFunction<ServerResponse> nestedRoute = RouterFunctions.route() .nest(RequestPredicates.path("/user"), builder -> builder.GET(this::listUsers) .POST(this::createUser)) .build();- Parameters:
- predicate- the predicate to test
- builderConsumer- consumer for a- Builderthat provides the nested router function
- Returns:
- this builder
- See Also:
 
- 
pathRouterFunctions.Builder path(String pattern, Supplier<RouterFunction<ServerResponse>> routerFunctionSupplier) Route to the supplied router function if the given path prefix pattern applies. This method can be used to create nested routes, where a group of routes share a common path prefix. Specifically, this method can be used to merge externally defined router functions under a path prefix.For instance, the following example creates a nested route with a "/user" path predicate that delegates to the router function defined in userController, and with a "/order" path that delegates toorderController.RouterFunction<ServerResponse> nestedRoute = RouterFunctions.route() .path("/user", userController::routerFunction) .path("/order", orderController::routerFunction) .build();- Parameters:
- pattern- the pattern to match to
- routerFunctionSupplier- supplier for the nested router function to delegate to if the pattern matches
- Returns:
- this builder
 
- 
pathRoute to a built router function if the given path prefix pattern applies. This method can be used to create nested routes, where a group of routes share a common path prefix.For instance, the following example creates a nested route with a "/user" path predicate, so that GET requests for "/user" will list users, and POST request for "/user" will create a new user. RouterFunction<ServerResponse> nestedRoute = RouterFunctions.route() .path("/user", builder -> builder.GET(this::listUsers) .POST(this::createUser)) .build();- Parameters:
- pattern- the pattern to match to
- builderConsumer- consumer for a- Builderthat provides the nested router function
- Returns:
- this builder
 
- 
filterFilters all routes created by this builder with the given filter function. Filter functions are typically used to address cross-cutting concerns, such as logging, security, etc.For instance, the following example creates a filter that returns a 401 Unauthorized response if the request does not contain the necessary authentication headers. RouterFunction<ServerResponse> filteredRoute = RouterFunctions.route() .GET("/user", this::listUsers) .filter((request, next) -> { // check for authentication headers if (isAuthenticated(request)) { return next.handle(request); } else { return ServerResponse.status(HttpStatus.UNAUTHORIZED).build(); } }) .build();- Parameters:
- filterFunction- the function to filter all routes built by this builder
- Returns:
- this builder
 
- 
beforeFilter the request object for all routes created by this builder with the given request processing function. Filters are typically used to address cross-cutting concerns, such as logging, security, etc.For instance, the following example creates a filter that logs the request before the handler function executes. RouterFunction<ServerResponse> filteredRoute = RouterFunctions.route() .GET("/user", this::listUsers) .before(request -> { log(request); return request; }) .build();- Parameters:
- requestProcessor- a function that transforms the request
- Returns:
- this builder
 
- 
afterRouterFunctions.Builder after(BiFunction<ServerRequest, ServerResponse, ServerResponse> responseProcessor) Filter the response object for all routes created by this builder with the given response processing function. Filters are typically used to address cross-cutting concerns, such as logging, security, etc.For instance, the following example creates a filter that logs the response after the handler function executes. RouterFunction<ServerResponse> filteredRoute = RouterFunctions.route() .GET("/user", this::listUsers) .after((request, response) -> { log(response); return response; }) .build();- Parameters:
- responseProcessor- a function that transforms the response
- Returns:
- this builder
 
- 
onErrorRouterFunctions.Builder onError(Predicate<Throwable> predicate, BiFunction<Throwable, ServerRequest, ServerResponse> responseProvider) Filters all exceptions that match the predicate by applying the given response provider function.For instance, the following example creates a filter that returns a 500 response status when an IllegalStateExceptionoccurs.RouterFunction<ServerResponse> filteredRoute = RouterFunctions.route() .GET("/user", this::listUsers) .onError(e -> e instanceof IllegalStateException, (e, request) -> ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR).build()) .build();- Parameters:
- predicate- the type of exception to filter
- responseProvider- a function that creates a response
- Returns:
- this builder
 
- 
onErrorRouterFunctions.Builder onError(Class<? extends Throwable> exceptionType, BiFunction<Throwable, ServerRequest, ServerResponse> responseProvider) Filters all exceptions of the given type by applying the given response provider function.For instance, the following example creates a filter that returns a 500 response status when an IllegalStateExceptionoccurs.RouterFunction<ServerResponse> filteredRoute = RouterFunctions.route() .GET("/user", this::listUsers) .onError(IllegalStateException.class, (e, request) -> ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR).build()) .build();- Parameters:
- exceptionType- the type of exception to filter
- responseProvider- a function that creates a response
- Returns:
- this builder
 
- 
withAttributeAdd an attribute with the given name and value to the last route built with this builder.- Parameters:
- name- the attribute name
- value- the attribute value
- Returns:
- this builder
- Since:
- 5.3
 
- 
withAttributesManipulate the attributes of the last route built with the given consumer.The map provided to the consumer is "live", so that the consumer can be used to overwrite existing attributes, remove attributes, or use any of the other Mapmethods.- Parameters:
- attributesConsumer- a function that consumes the attributes map
- Returns:
- this builder
- Since:
- 5.3
 
- 
buildRouterFunction<ServerResponse> build()Builds theRouterFunction. All created routes are composed with one another, and filters (if any) are applied to the result.- Returns:
- the built router function
 
 
-