The router function

The router function is responsible for routing incoming requests to the correct handler function. If we compare this to the annotation approach, then it is analogous to the @RequestMapping annotation.

 A request is matched using RequestPredicate, which tries to validate the intended matching criteria. Our previously created helloHandler can be configured in the following manner:

RouterFunction<ServerResponse> route =          RouterFunctions.route(RequestPredicates.path("/hello"),hellowHandler);

The preceding code is doing the following:

  1. It registers a predicate for the /hello path
  2. If a request matches this path, the router invokes helloHandler

If we look at RequestPredicate, this is a functional interface in which we need to ...

Get Hands-On Reactive Programming with Reactor now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.