HttpHandler

Now that we have mapped a request using the handler and router, the only step left is to start the server. SpringWebFlux enables us to programmatically start the server. In order to do so, we have to get HttpHandler from RouterFunction and then start the required server:

HttpHandler httpHandler = RouterFunctions.toHttpHandler(helloRoute);ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(httpHandler);HttpServer server = HttpServer.create("127.0.0.1", 8080);server.newHandler(adapter).block();

The preceding code is specific to Netty, as we are using reactor-netty in our current example. In the preceding code, we are doing the following:

  • Converting the helloRoute to a HttpHandler using RoterFunctions.toHttpHandler ...

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.