๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ spring โ€บ spring web โ€บ spring webclient
Spring WebClient | Baeldung
November 25, 2025 - Simply put, WebClient is an interface representing the main entry point for performing web requests. It was created as part of the Spring Web Reactive module and will be replacing the classic RestTemplate in these scenarios.
๐ŸŒ
Medium
medium.com โ€บ @ayoubseddiki132 โ€บ mastering-webclient-in-spring-boot-a-complete-guide-31482263bc92
Mastering WebClient in Spring Boot: A Complete Guide | by Ayoub seddiki | Medium
January 29, 2025 - <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> </dependencies> Now, create a WebClient Bean in your configuration class: @Configuration public class WebClientConfig { @Bean public WebClient webClient() { return WebClient.builder() .baseUrl("https://api.example.com") .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) .build(); } }
Discussions

Sending HTTP requests and beyond with Spring WebClient
The fun starts with sending OAuth-2-requests. That was painful the first time. More on reddit.com
๐ŸŒ r/java
8
59
May 28, 2021
rest - Spring WebClient Post method Body - Stack Overflow
There's various tutorials around (hellokoding.com/spring-webclient-tutorial-with-examples) - but the docs are definitely worth a read if you can stomach it, they have the most complete & up-to-date info. More on stackoverflow.com
๐ŸŒ stackoverflow.com
java - Spring Webflux : Webclient : Get body on error - Stack Overflow
To add as a viable solution since it has not been suggested yet, just use a global exception handler for any WebClientResponseException thrown by WebClient IF called via a Spring Controller (from https://www.callicoder.com/spring-5-reactive-webclient-webtestclient-examples/): More on stackoverflow.com
๐ŸŒ stackoverflow.com
How does the community like the fact that Spring 5 goes "reactive" for restful?
There is a ton of clients which are not reactive. Use the one you like. For example I've used Java's HTTP client. More on reddit.com
๐ŸŒ r/java
27
33
November 27, 2021
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ springboot โ€บ spring-boot-webclient-with-example
Spring Boot - WebClient with Example - GeeksforGeeks
July 23, 2025 - The DefaultWebClient class implements this WebClient interface. ... Add this dependency to the pom.xml file. <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency>
๐ŸŒ
Spring
spring.academy โ€บ guides โ€บ spring-webclient-gs
Getting Started with Spring WebClient
Register ยท Log In ยท Spring Academy ยท Loading ยท Guides|Courses|Learning Paths|Community|Instructors|About|Give Feedback ยท Contact|FAQs|Terms|Privacy|Your California Privacy Rights ยท Unlock your full potential with Spring courses designed by experts ยท Copyright ยฉ 2005-2026 Broadcom.
๐ŸŒ
HowToDoInJava
howtodoinjava.com โ€บ home โ€บ spring webflux โ€บ spring webclient (with hands-on examples)
Spring WebClient (with Hands-On Examples)
September 14, 2023 - Spring WebFlux configures the default memory limit for buffering data in-memory to 256KB. If this limit is exceeded in any case then we will encounter DataBufferLimitException error.
๐ŸŒ
Spring
docs.spring.io โ€บ spring-framework โ€บ docs โ€บ current โ€บ javadoc-api โ€บ org โ€บ springframework โ€บ web โ€บ reactive โ€บ function โ€บ client โ€บ WebClient.html
WebClient (Spring Framework 7.0.9 API)
public interface WebClient ยท Non-blocking, reactive client to perform HTTP requests, exposing a fluent, reactive API over underlying HTTP client libraries such as Reactor Netty. Use static factory methods create() or create(String), or builder() to prepare an instance. For examples with a response body see: retrieve() exchangeToMono() exchangeToFlux() For examples with a request body see: bodyValue(Object) body(Publisher,Class) Since: 5.0 ยท
๐ŸŒ
Vinsguru
blog.vinsguru.com โ€บ spring-webclient
Spring WebClient Example | Vinsguru
November 28, 2023 - Letโ€™s create a simple model for Post. I use lombok for getters and setters. ... Lets initialize few variables. private static final String BASE_URL = "http://localhost:3000/"; private WebClient webClient;
Find elsewhere
๐ŸŒ
Medium
medium.com โ€บ @vino7tech โ€บ spring-webflux-webclient-explained-with-real-time-scenarios-d62410080b88
Spring WebFlux โ€” WebClient Explained with Real-Time Scenarios | by Vinotech | Medium
January 7, 2026 - Spring WebFlux introduces WebClient, a non-blocking, reactive HTTP client, designed to solve these scalability problems. This blog explains WebClient from basics to advanced, with real-time scenarios, code examples, and interview-ready explanations.
๐ŸŒ
Stefankreidel
stefankreidel.io โ€บ blog โ€บ spring-webmvc-with-webclient
Spring Web MVC + WebClient: How they work Together โ€“ Stefan Kreidel
In our minimal example, task just requires the received response to be handed over to our original calling request. You probably noticed that this request has been waiting patiently the entire time. Because of this, our application is still inherently blocking even though we used non-blocking mechanisms to handle outgoing HTTP communication. Combining Spring Web MVC and WebClient on a code level is pretty straight forward to get started, although, it is admittedly not intuitive at first:
๐ŸŒ
Spring
docs.spring.io โ€บ spring-framework โ€บ reference โ€บ web โ€บ webflux-webclient โ€บ client-body.html
Request Body :: Spring Framework
var resource: Resource = ... var result: Mono<String> = webClient .post() .uri("https://example.com") .body( Flux.concat( FormPartEvent.create("field", "field value"), FilePartEvent.create("file", resource) ) ) .retrieve() .bodyToMono()
๐ŸŒ
Spring
docs.spring.io โ€บ spring-boot โ€บ docs โ€บ 2.0.3.RELEASE โ€บ reference โ€บ html โ€บ boot-features-webclient.html
34. Calling REST Services with WebClient
You can create your own client instance with the builder, WebClient.create(). See the relevant section on WebClient. Spring Boot creates and pre-configures such a builder for you. For example, client HTTP codecs are configured in the same fashion as the server ones (see WebFlux HTTP codecs ...
๐ŸŒ
OneUptime
oneuptime.com โ€บ home โ€บ blog โ€บ how to build reactive http clients with webclient in spring
How to Build Reactive HTTP Clients with WebClient in Spring
January 25, 2026 - WebClient provides a modern, non-blocking approach to HTTP communication in Spring applications. Key takeaways: Configure WebClient with appropriate timeouts and connection settings
๐ŸŒ
Reddit
reddit.com โ€บ r/java โ€บ sending http requests and beyond with spring webclient
r/java on Reddit: Sending HTTP requests and beyond with Spring WebClient
May 28, 2021 - How to get started using Spring WebClient to talk to REST APIs. Archived post. New comments cannot be posted and votes cannot be cast. Share ... The fun starts with sending OAuth-2-requests. That was painful the first time. ... Yeah, oauth requests are a fucking nightmare. Our code base it littered with cookie-manipulation utilities. ... We have a need to make oauth 2 requests. Any examples ...
๐ŸŒ
Medium
medium.com โ€บ @pradeepisuru31 โ€บ mastering-spring-webclient-a693f90447f0
Mastering Spring WebClient. A Comprehensive Guide forโ€ฆ | by Isuru Pradeep | Medium
June 22, 2025 - // Simplest form WebClient client = WebClient.create(); // With a base URL WebClient client = WebClient.create("https://api.example.com"); // Using Builder (recommended for customization) WebClient client = WebClient.builder() .baseUrl("htt...
Top answer
1 of 2
14

Here's what i've tried to do but it gives me HTTP code 500

Most likely because you're sending the wrong data in a mixture of wrong formats with the wrong type:

  • You're using multipart form data, not JSON
  • You're then setting the request parameter as a JSON string (q)
  • The JSON string you're using in q isn't even valid (it's at least missing an opening curly brace) - and handwriting JSON is almost universally a bad idea, leverage a framework to do it for you instead.

Instead, the normal thing to do would be to create a POJO structure that maps to your request, so:

public class CrawlRequest {

    private CrawlInnerRequest request;
    @JsonProperty("spider_name")
    private String spiderName;

    //....add the getters / setters
}

public class CrawlInnerRequest {

    private String url;
    private String callback;
    @JsonProperty("dont_filter")
    private String dontFilter;

    //....add the getters / setters
}

...then simply create a CrawlRequest, set the values as you wish, then in your post call use:

.body(BodyInserters.fromValue(crawlRequest))

This is a rather fundamental, basic part of using a WebClient. I'd suggest reading around more widely to give yourself a better understanding of the fundamentals, it will help tremendously in the long run.

2 of 2
4

For me following code worked:

public String wcPost(){

    Map<String, String> bodyMap = new HashMap();
    bodyMap.put("key1","value1");
 

    WebClient client = WebClient.builder()
            .baseUrl("domainURL")
            .build();


    String responseSpec = client.post()
            .uri("URI")
            .headers(h -> h.setBearerAuth("token if any"))
            .body(BodyInserters.fromValue(bodyMap))
            .exchange()
            .flatMap(clientResponse -> {
                if (clientResponse.statusCode().is5xxServerError()) {
                    clientResponse.body((clientHttpResponse, context) -> {
                        return clientHttpResponse.getBody();
                    });
                    return clientResponse.bodyToMono(String.class);
                }
                else
                    return clientResponse.bodyToMono(String.class);
            })
            .block();

    return responseSpec;
}
๐ŸŒ
Medium
medium.com โ€บ @ia_taras โ€บ efficient-api-communication-with-spring-webclient-5c5dea18a6ba
Efficient API Communication with Spring WebClient | by Taras Ivashchuk | Medium
October 14, 2024 - ExchangeFilterFunction is a functional interface in Spring WebFlux, that gives you the ability to intercept and modify requests and responses. For example, features like logging, authentication, error handling, metrics, and caching can be plugged into your HTTP calls with the help of this ability without altering the core application logic.
๐ŸŒ
HowToDoInJava
howtodoinjava.com โ€บ home โ€บ spring webflux โ€บ spring boot webclient post example
Spring Boot WebClient POST Example
September 14, 2023 - Spring Boot WebClient example discusses sending HTTP POST requests, submitting form data and handling the response status, headers and body.
Top answer
1 of 16
39

Don't we have onStatus()?

    public Mono<Void> cancel(SomeDTO requestDto) {
        return webClient.post().uri(SOME_URL)
                .body(fromObject(requestDto))
                .header("API_KEY", properties.getApiKey())
                .retrieve()
                .onStatus(HttpStatus::isError, response -> {
                    logTraceResponse(log, response);
                    return Mono.error(new IllegalStateException(
                            String.format("Failed! %s", requestDto.getCartId())
                    ));
                })
                .bodyToMono(Void.class)
                .timeout(timeout);
    }

And:

    public static void logTraceResponse(Logger log, ClientResponse response) {
        if (log.isTraceEnabled()) {
            log.trace("Response status: {}", response.statusCode());
            log.trace("Response headers: {}", response.headers().asHttpHeaders());
            response.bodyToMono(String.class)
                    .publishOn(Schedulers.elastic())
                    .subscribe(body -> log.trace("Response body: {}", body));
        }
    }
2 of 16
38

I prefer to use the methods provided by the ClientResponse to handle http errors and throw exceptions:

WebClient.create()
         .post()
         .uri( url )
         .body( bodyObject == null ? null : BodyInserters.fromValue( bodyObject ) )
         .accept( MediaType.APPLICATION_JSON )
         .headers( headers )
         .exchange()
         .flatMap( clientResponse -> {
             //Error handling
             if ( clientResponse.statusCode().isError() ) { // or clientResponse.statusCode().value() >= 400
                 return clientResponse.createException().flatMap( Mono::error );
             }
             return clientResponse.bodyToMono( clazz )
         } )
         //You can do your checks: doOnError (..), onErrorReturn (..) ...
         ...

In fact, it's the same logic used in the DefaultResponseSpec of DefaultWebClient to handle errors. The DefaultResponseSpec is an implementation of ResponseSpec that we would have if we made a retrieve() instead of exchange().

๐ŸŒ
rieckpil
rieckpil.de โ€บ home โ€บ spring framework tutorials โ€บ setup and examples for the spring webflux webclient
Setup and Examples for the Spring WebFlux WebClient
May 19, 2021 - Learn how to effectively use and configure the Spring 5 WebClient (WebFlux) from different examples: interceptors headers, retries, timeouts
๐ŸŒ
JavaTechOnline
javatechonline.com โ€บ home โ€บ webclient in spring boot
WebClient In Spring Boot - JavaTechOnline
May 3, 2026 - Sometimes we may have to implement a complex method using WebClient in Spring Boot. For example, below code snippet demonstrates a complex POST request sent by WebClient in Spring Boot.