Skip to content

Commit

Permalink
Add an "/echo" endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
bclozel committed May 19, 2017
1 parent 871c4e3 commit 54654b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ public Mono<ServerResponse> hello(ServerRequest request) {
return ok().contentType(TEXT_PLAIN)
.body(BodyInserters.fromObject("Hello Spring!"));
}

public Mono<ServerResponse> echo(ServerRequest request) {
return ok().contentType(TEXT_PLAIN)
.body(request.bodyToMono(String.class), String.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@

import static org.springframework.http.MediaType.TEXT_PLAIN;
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RequestPredicates.POST;
import static org.springframework.web.reactive.function.server.RequestPredicates.accept;
import static org.springframework.web.reactive.function.server.RequestPredicates.contentType;

@Configuration
public class QuoteRouter {

@Bean
public RouterFunction<ServerResponse> route(QuoteHandler quoteHandler) {
return RouterFunctions
.route(GET("/hello").and(accept(TEXT_PLAIN)), quoteHandler::hello);
.route(GET("/hello").and(accept(TEXT_PLAIN)), quoteHandler::hello)
.andRoute(POST("/echo").and(accept(TEXT_PLAIN).and(contentType(TEXT_PLAIN))), quoteHandler::echo);
}
}

0 comments on commit 54654b5

Please sign in to comment.