Skip to content

This is a later spring web (2.2.0.BUILD-SNAPSHOT) with functional servlet functionality!

Notifications You must be signed in to change notification settings

daggerok/spring-boot-functional-servlet-example

Repository files navigation

Functional Servlet MVC Build Status

This is a later spring web (2.2.0.BUILD-SNAPSHOT) with functional servlet functionality!

Key items

Functional Servlet based Routes

@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();
  }
}

Build, run and test

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

zip sources (out of topic)

./gradlew sources # or ./mvnw package

links: