Top Description Methods
org.springframework.web.servlet.function

public Interface RouterFunction<T extends ServerResponse>

Known Direct Implementers
org.springframework.web.servlet.function.RouterFunctions.AbstractRouterFunction, org.springframework.web.servlet.function.RouterFunctions.FilteredRouterFunction
Annotations
@FunctionalInterface
Type Parameters
<T>
the type of the handler function to route to
Imports
java.util.LinkedHashMap, .Map, .Optional, java.util.function.Consumer, org.springframework.util.Assert

Represents a function that routes to a handler function.
Author
Arjen Poutsma
Since
5.2
See Also
RouterFunctions

Method Summary

Modifier and TypeMethod and Description
public default void
accept(RouterFunctions.Visitor
the visitor to accept
visitor
)

Accept the given visitor.

public default RouterFunction<T>

Returns:

a composed function that first routes with this function and then the other function if this function has no result
and
(RouterFunction<T>
the function of type T to apply when this function has no result
other
)

Return a composed routing function that first invokes this function, and then invokes the other function (of the same response type T) if this route had no result.

public default RouterFunction<T>

Returns:

a composed function that route to routerFunction if this route does not match and if predicate applies
andNest
(RequestPredicate
the predicate to test if this route does not match
predicate
,
RouterFunction<T>
the router function to route to if this route does not match and the predicate applies
routerFunction
)

Return a composed routing function that routes to the given router function if this route does not match and the given request predicate applies.

public default RouterFunction<?>

Returns:

a composed function that first routes with this function and then the other function if this function has no result
andOther
(RouterFunction<?>
the function to apply when this function has no result
other
)

Return a composed routing function that first invokes this function, and then invokes the other function (of a different response type) if this route had no result.

public default RouterFunction<T>

Returns:

a composed function that route to handlerFunction if this route does not match and if predicate applies
andRoute
(RequestPredicate
the predicate to test if this route does not match
predicate
,
HandlerFunction<T>
the handler function to route to if this route does not match and the predicate applies
handlerFunction
)

Return a composed routing function that routes to the given handler function if this route does not match and the given request predicate applies.

public default <
the filter return type
S extends ServerResponse
>
RouterFunction<S>

Returns:

the filtered routing function
filter
(HandlerFilterFunction<T, S>
the filter to apply
filterFunction
)

Filter all handler functions routed by this function with the given filter function.

public Optional<HandlerFunction<T>>

Returns:

an Optional describing the HandlerFunction that matches this request, or an empty Optional if there is no match
route
(ServerRequest
the request to route
request
)

Return the handler function that matches the given request.

public default RouterFunction<T>

Returns:

a function that has the specified attributes
withAttribute
(String
the attribute name
name
,
Object
the attribute value
value
)

Return a new routing function with the given attribute.

public default RouterFunction<T>

Returns:

this builder
withAttributes
(Consumer<Map<String, Object>>
a function that consumes the attributes map
attributesConsumer
)

Return a new routing function with attributes manipulated with the given consumer.

Method Detail

acceptback to summary
public default void accept(RouterFunctions.Visitor visitor)

Accept the given visitor. Default implementation calls RouterFunctions.Visitor#unknown(RouterFunction); composed RouterFunction implementations are expected to call accept for all components that make up this router function.

Parameters
visitor:RouterFunctions.Visitor

the visitor to accept

andback to summary
public default RouterFunction<T> and(RouterFunction<T> other)

Return a composed routing function that first invokes this function, and then invokes the other function (of the same response type T) if this route had no result.

Parameters
other:RouterFunction<T>

the function of type T to apply when this function has no result

Returns:RouterFunction<T>

a composed function that first routes with this function and then the other function if this function has no result

See Also
andOther(RouterFunction)
andNestback to summary
public default RouterFunction<T> andNest(RequestPredicate predicate, RouterFunction<T> routerFunction)

Return a composed routing function that routes to the given router function if this route does not match and the given request predicate applies. This method is a convenient combination of and(RouterFunction) and RouterFunctions#nest(RequestPredicate, RouterFunction).

Parameters
predicate:RequestPredicate

the predicate to test if this route does not match

routerFunction:RouterFunction<T>

the router function to route to if this route does not match and the predicate applies

Returns:RouterFunction<T>

a composed function that route to routerFunction if this route does not match and if predicate applies

andOtherback to summary
public default RouterFunction<?> andOther(RouterFunction<?> other)

Return a composed routing function that first invokes this function, and then invokes the other function (of a different response type) if this route had no result.

Parameters
other:RouterFunction<?>

the function to apply when this function has no result

Returns:RouterFunction<?>

a composed function that first routes with this function and then the other function if this function has no result

See Also
and(RouterFunction)
andRouteback to summary
public default RouterFunction<T> andRoute(RequestPredicate predicate, HandlerFunction<T> handlerFunction)

Return a composed routing function that routes to the given handler function if this route does not match and the given request predicate applies. This method is a convenient combination of and(RouterFunction) and RouterFunctions#route(RequestPredicate, HandlerFunction).

Parameters
predicate:RequestPredicate

the predicate to test if this route does not match

handlerFunction:HandlerFunction<T>

the handler function to route to if this route does not match and the predicate applies

Returns:RouterFunction<T>

a composed function that route to handlerFunction if this route does not match and if predicate applies

filterback to summary
public default <S extends ServerResponse> RouterFunction<S> filter(HandlerFilterFunction<T, S> filterFunction)

Filter all handler functions routed by this function with the given filter function.

Parameters
<S>
the filter return type
filterFunction:HandlerFilterFunction<T, S>

the filter to apply

Returns:RouterFunction<S>

the filtered routing function

routeback to summary
public Optional<HandlerFunction<T>> route(ServerRequest request)

Return the handler function that matches the given request.

Parameters
request:ServerRequest

the request to route

Returns:Optional<HandlerFunction<T>>

an Optional describing the HandlerFunction that matches this request, or an empty Optional if there is no match

withAttributeback to summary
public default RouterFunction<T> withAttribute(String name, Object value)

Return a new routing function with the given attribute.

Parameters
name:String

the attribute name

value:Object

the attribute value

Returns:RouterFunction<T>

a function that has the specified attributes

Since
5.3
withAttributesback to summary
public default RouterFunction<T> withAttributes(Consumer<Map<String, Object>> attributesConsumer)

Return a new routing function with attributes manipulated 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 Map methods.

Parameters
attributesConsumer:Consumer<Map<String, Object>>

a function that consumes the attributes map

Returns:RouterFunction<T>

this builder

Since
5.3