Skip to content

Commit c8724c1

Browse files
authored
BAEL-4698 Added HTTP Response Body as String with WebClient (eugenp#11083)
1 parent bfe5889 commit c8724c1

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

httpclient-2/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
<version>${spring-boot.version}</version>
4444
<scope>test</scope>
4545
</dependency>
46+
<!-- Webclient -->
47+
<dependency>
48+
<groupId>org.springframework.boot</groupId>
49+
<artifactId>spring-boot-starter-webflux</artifactId>
50+
<version>${spring-boot.version}</version>
51+
</dependency>
4652
</dependencies>
4753

4854
<build>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.baeldung.httpclient.readresponsebodystring;
2+
3+
import org.junit.Test;
4+
import org.springframework.web.reactive.function.client.WebClient;
5+
import reactor.core.publisher.Mono;
6+
7+
public class SpringWebClientUnitTest {
8+
public static final String DUMMY_URL = "https://postman-echo.com/get";
9+
10+
@Test
11+
public void whenUseWebClientRetrieve_thenCorrect() {
12+
WebClient webClient = WebClient.create(DUMMY_URL);
13+
Mono<String> body = webClient.get().retrieve().bodyToMono(String.class);
14+
String s = body.block();
15+
System.out.println(s);
16+
}
17+
}

0 commit comments

Comments
 (0)