This is a later spring web (2.2.0.BUILD-SNAPSHOT) with functional servlet functionality!
@Configuration
public class FunctionalRouter {
@Bean
public RouterFunction<ServerResponse> routes() {
return RouterFunctions.route()
.POST("/fn", request -> ServerResponse.ok().body("Functional hello!"))
.GET("/**", request -> ServerResponse.ok().body("_self: " + request.path()))
.filter((request, next) -> {
var response = next.handle(request);
var headers = HttpHeaders.writableHttpHeaders(response.headers());
headers.add("X-FUNCTIONAL", "It's fucking awesome!");
return response;
})
.build();
}
}
./mvnw # or: ./gradlew
java -jar ./target/*.jar # or: ./build/libs/*.jar
http :8080/fn body=world
http :8080/mvc/
http :8080/mvc body=hello
http :8080/fn/
./gradlew sources # or ./mvnw package
links: