Skip to content

Instantly share code, notes, and snippets.

@rj93
Created January 24, 2021 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rj93/c9b30f4d11cee145346c1c8b63908ea3 to your computer and use it in GitHub Desktop.
Save rj93/c9b30f4d11cee145346c1c8b63908ea3 to your computer and use it in GitHub Desktop.
Hello Controller, that reaches out to Reddit to obtain the username.
@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