0

I want to separate the execution of an HTTP request from the parsing of the HTTP response body using Spring WebClient.

I want to write tests that test each of these concerns separately so that I can easily identify where an issue exists (in the execution of the request or in the parsing of the response body). I don't want the request call to fail because the response was a primitive string even though I was expecting JSON.

WebClient only seems to be able to execute a request and parse the response's body in one step:

var responseBody = client.get().uri(endpoint).retrieve().bodyToMono(String.class).block();

I want to do something like this:

var response = client.get().uri(endpoint).retrieve().block();
var responseBody = response.bodyToMono(String.class).block();
Krzysztof Czelusniak
  • 1,217
  • 4
  • 16
  • 26

0 Answers0