Skip to content

Commit 2d5864d

Browse files
Ryan Baxterrstoyanchev
andauthored
Use retrieve method
Co-authored-by: Rossen Stoyanchev <[email protected]>
1 parent 091eca9 commit 2d5864d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

app/src/main/java/com/example/demo/DemoApplication.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ public static void main(String[] args) {
2020

2121
@GetMapping
2222
public Mono<String> index() {
23-
return webClient.get().uri("http://k8s-workshop-name-service").exchange().flatMap(clientResponse -> {
24-
String host = clientResponse.headers().asHttpHeaders().get("k8s-host").get(0);
25-
return clientResponse.bodyToMono(String.class).flatMap(name -> Mono.just("Hello " + name + " from " + host));
26-
});
23+
return webClient.get().uri("http://k8s-workshop-name-service")
24+
.retrieve()
25+
.toEntity(String.class)
26+
.map(entity -> {
27+
String host = entity.getHeaders().get("k8s-host").get(0);
28+
return "Hello " + entity.getBody() + " from " + host;
29+
});
30+
2731
}
2832
}

0 commit comments

Comments
 (0)