I know sending a body with a GET request isn't the best idea but I'm trying to consume an existing API which requires it.
Sending a body with POST is straight-forward:
webClient.post()
.uri("/employees")
.body(Mono.just(empl), Employee.class)
.retrieve()
.bodyToMono(Employee.class);
It won't work with webClient.get()
though, because while the post()
method returns a WebClient.RequestBodyUriSpec
, the get()
method returns WebClient.RequestHeadersUriSpec<?>
, which doesn't seem to allow any body definitions.
I've found a workaround for Spring RestTemplate here: RestTemplate get with body, but had no luck finding any for the new WebClient.
.method(GET)
? – SoutacheCREATED
response without a location header). But I have to agree with Boris that sending a body with a get - while not strictly forbidden - is highly discouraged not not best practice. – Hosanna.method()
. – Acidulate