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 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.