This repository contains the sample code for Spring WebFlux’s functional web API and consists of the following building blocks:
-
An
Event
domain type and a corresponding repository exposing a tailable query method. -
An
ApplicationRunner
that creates a capped collection for events and inserts a new one every two seconds. -
A Spring WebFlux controller to produce both a Server-Sent Events and JSON stream.
-
A
User
domain type and a reactive repository mapped using Spring Data MongoDB. -
A
FunctionalWebController
to contain handler functions. -
An
@Bean
-Definition for aRouterFunction
that uses the functional API to configure the mappings of requests to theFunctionalWebController
.
$ git clone https://github.com/olivergierke/spring-five-functional-reactive
$ cd spring-five-functional-reactive
$ ./mvnw spring-boot:run
# To see the events inserted on the server streaming to the client
$ curl -H "Accept: text/event-stream" http://localhost:8080/events
# To trigger the functional controller
$ curl http://localhost:8080/users