daggerok / spring-boot-functional-servlet-example

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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:

About

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


Languages

Language:Java 75.8%Language:Kotlin 24.2%