WebClient makes it possible to perform reactive non-blocking HTTP requests in Spring applications. Use this tag for any questions involving its usage.
Questions tagged [spring-webclient]
992 questions
37
votes
3 answers
Spring boot Webclient's retrieve vs exchange
I have started using WebClient in my Spring boot project recently.
Can somebody throw some light on the differences/usages between exchange and retrieve methods in WebClient.
I understand that exchange returns Mono and retrieve…

Abdullah Khan
- 12,010
- 6
- 65
- 78
34
votes
4 answers
Spring WebClient: How to stream large byte[] to file?
It seems like it the Spring RestTemplate isn't able to stream a response directly to file without buffering it all in memory. What is the proper to achieve this using the newer Spring 5 WebClient?
WebClient client =…

Dave L.
- 9,595
- 7
- 43
- 69
30
votes
4 answers
How to set multiple headers at once in Spring WebClient?
I was trying to set headers to my rest client but every time I have to write
webclient.get().uri("blah-blah")
.header("key1", "value1")
.header("key2", "value2")...
How can I set all headers at the same time using headers()…

Amit Kumar
- 313
- 1
- 3
- 4
29
votes
2 answers
How to post request with spring boot web-client for Form data for content type application/x-www-form-urlencoded
How To use spring boot webclient for posting request with content type application/x-www-form-urlencoded
sample curl request with content type `application/x-www-form-urlencoded'
--header 'Content-Type: application/x-www-form-urlencoded'…

Niraj Sonawane
- 10,225
- 10
- 75
- 104
27
votes
7 answers
spring webclient: retry with backoff on specific error
i'd like to retry the request 3 times after waiting 10sec when response is 5xx. but i don't see a method that I can use. On object
WebClient.builder()
.baseUrl("...").build().post()
.retrieve().bodyToMono(...)
i can…

piotrek
- 13,982
- 13
- 79
- 165
24
votes
3 answers
Does the use of Spring Webflux's WebClient in a blocking application design cause a larger use of resources than RestTemplate
I am working on several spring-boot applications which have the traditional pattern of thread-per-request. We are using Spring-boot-webflux to acquire WebClient to perform our RESTful integration between the applications. Hence our application…

ODDminus1
- 544
- 1
- 3
- 11
22
votes
2 answers
PrematureCloseException: Connection prematurely closed
im using Web-flux/Reactive and Webclient, running it on tomcat and spring-boot.
Everything works fine. I read a lot about it. The problem seems to be that whenever you use webclient, you have to return or use the response, otherwise it will close…

Douglas Santos
- 515
- 1
- 4
- 12
22
votes
3 answers
Adding a retry all requests of WebClient
we have a server to retrieve a OAUTH token, and the oauth token is added to each request via WebClient.filter method
e.g
webClient
.mutate()
.filter((request, next) -> tokenProvider.getBearerToken()
…

Kevin Hussey
- 1,582
- 1
- 10
- 17
20
votes
3 answers
Spring WebFlux 5.3.0 - WebClient.exchangeToMono()
I've just upgraded to Webflux 5.3.0, and noticed that WebClient.exchange() method is now deprecated (link) in favor of new methos .exchangeToMono() and .exchangeToFlux()
I had this code:
webClient
.method(request.method)
.uri(request.path)
…

Larik Borts
- 353
- 1
- 3
- 8
19
votes
5 answers
Proxy setting not working with Spring WebClient
My following WebClient is working fine with internet connection but not through our proxy connection.
WebClient webClient = WebClient.builder()
.baseUrl("https://targetsite.com")
.build();
webClient.post()
…

Krishna
- 609
- 1
- 6
- 17
16
votes
3 answers
SpringBoot FeignClient vs WebClient
I want to consume a couple of rest services. Before, I used RestTemplate, but now I want to know The main differences between Spring Boot FeignClient and WebClient.
When should they be used?

Tohid Makari
- 1,700
- 3
- 15
- 29
16
votes
7 answers
WebClient - how to get request body?
I've started using WebClient and I'm adding logging of request/response using filter method:
WebClient.builder()
.baseUrl(properties.getEndpoint())
.filter((request, next) -> {
// logging
request.body()
})
…

Marcin Szulc
- 1,171
- 1
- 10
- 21
14
votes
2 answers
Spring WebClient set Bearer auth token in header
Following scenario:
I have two Microservices A and B. Service A is a Bearer client that has an open api and receives requests from clients that have to be authorized by keycloak. Now I want to send an authorized Request from Service A to Service B,…

FishingIsLife
- 1,972
- 3
- 28
- 51
14
votes
1 answer
Add query parameter in WebClient request
I am using Spring WebFlux where I am taking request and using same request to call another service. But I am not sure how to add query parameters. This is my code
@RequestMapping(value= ["/ptta-service/**"])
suspend fun executeService(request:…

nicholasnet
- 2,117
- 2
- 24
- 46
13
votes
2 answers
Looking for an alternative of retryWhen which is now Deprecated
I'm facing an issue with WebClient and reactor-extra. Indeed, I have the following method :
public Employee getEmployee(String employeeId) {
return webClient.get()
.uri(FIND_EMPLOYEE_BY_ID_URL, employeeId)
…

Pierre Jones
- 620
- 1
- 11
- 24