Last active
November 29, 2020 19:51
-
-
Save jonashackt/b03bfbe4d49d091319928a5edb9de0f4 to your computer and use it in GitHub Desktop.
DevOps lecture: Spring Boot reactive router & handler code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.springframework.context.annotation.Bean; | |
| import org.springframework.http.MediaType; | |
| import org.springframework.stereotype.Component; | |
| import org.springframework.web.reactive.function.BodyInserters; | |
| import org.springframework.web.reactive.function.server.*; | |
| import reactor.core.publisher.Mono; | |
| @Component | |
| public class HelloRouter { | |
| public Mono<ServerResponse> hello(ServerRequest serverRequest) { | |
| return ServerResponse | |
| .ok() | |
| .contentType(MediaType.TEXT_PLAIN) | |
| .body(BodyInserters.fromValue("Hello World")); | |
| } | |
| @Bean | |
| public RouterFunction<ServerResponse> route() { | |
| return RouterFunctions.route( | |
| RequestPredicates.GET("/hello").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), | |
| serverRequest -> hello(serverRequest) | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment