The choice between WebClient.builder() and WebClient.create() depends on the level of customization required for the WebClient instance.
-
WebClient.create():This static factory method provides a quick way to create a WebClient instance with default settings. It can also accept a base URL as an argument, simplifying the creation of clients for a specific endpoint. Use this when minimal configuration is needed.
-
WebClient.builder():This method returns a WebClient.Builder instance, offering extensive customization options. It allows for configuring various aspects of the WebClient, such as:
- baseUrl(): Setting a base URL for all requests made by this client.
- defaultHeader(): Adding default headers to all requests.
- filter(): Applying custom filters for request/response modification.
- clientConnector(): Customizing the underlying HTTP client (e.g., configuring timeouts, SSL).
- codecs(): Adjusting codec settings, such as maxInMemorySize.
Conclusion:
- Use WebClient.create() for simple scenarios where default configurations suffice or only a base URL is required.
- Use WebClient.builder() when fine-grained control over the WebClient's behavior is necessary, enabling advanced configurations like timeouts, custom headers, or client connectors.
'【 개발 이야기 】' 카테고리의 다른 글
[RxJava] Observable<T>와 MaybeSource<T> (0) | 2025.07.22 |
---|---|
HTTP method (6) | 2025.07.21 |
Filter의 Flux<DataBuffer>에 대해 알아보자 (0) | 2025.07.14 |
[Spring Boot] WebFliter의 테스트 코드를 DefaultServerWebExchange사용하여 작성해보자 (4) | 2025.07.10 |
실전!! companion object를 사용한 공식문서 리팩터링 (1) | 2025.07.07 |