Created
January 24, 2021 19:50
-
-
Save rj93/c9b30f4d11cee145346c1c8b63908ea3 to your computer and use it in GitHub Desktop.
Hello Controller, that reaches out to Reddit to obtain the username.
This file contains 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
@RestController | |
public class HelloController { | |
private final WebClient webClient; | |
public HelloController(@Qualifier("redditWebClient") WebClient webClient) { | |
this.webClient = webClient; | |
} | |
@GetMapping | |
public Mono<String> hello() { | |
return getUsername() | |
.map(name -> "Hello, " + name); | |
} | |
private Mono<String> getUsername() { | |
return webClient.get() | |
.uri("/api/v1/me") | |
.retrieve() | |
.bodyToMono(new ParameterizedTypeReference<Map<String, Object>>() {}) | |
.map(responseBody -> "u/" + responseBody.get("name")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment