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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.