public interface WebClient
// Initialize the client WebClient client = WebClient.create("http://abc.com"); // Perform requests... Mono<String> result = client.get() .uri("/foo") .exchange() .then(response -> response.bodyToMono(String.class));
Modifier and Type | Interface and Description |
---|---|
static interface |
WebClient.Builder
A mutable builder for a
WebClient . |
static interface |
WebClient.HeaderSpec
Contract for specifying request headers leading up to the exchange.
|
static interface |
WebClient.UriSpec
Contract for specifying the URI for a request.
|
Modifier and Type | Method and Description |
---|---|
static WebClient.Builder |
builder()
Obtain a
WebClient builder. |
static WebClient |
create()
Create a new
WebClient with no default, shared preferences across
requests such as base URI, default headers, and others. |
static WebClient |
create(java.lang.String baseUrl)
Configure a base URI for requests performed through the client for
example to avoid repeating the same host, port, base path, or even
query parameters with every request.
|
WebClient.UriSpec |
delete()
Prepare an HTTP DELETE request.
|
WebClient |
filter(ExchangeFilterFunction filterFunction)
Filter the client with the given
ExchangeFilterFunction . |
WebClient.UriSpec |
get()
Prepare an HTTP GET request.
|
WebClient.UriSpec |
head()
Prepare an HTTP HEAD request.
|
WebClient.UriSpec |
options()
Prepare an HTTP OPTIONS request.
|
WebClient.UriSpec |
patch()
Prepare an HTTP PATCH request.
|
WebClient.UriSpec |
post()
Prepare an HTTP POST request.
|
WebClient.UriSpec |
put()
Prepare an HTTP PUT request.
|
WebClient.UriSpec get()
WebClient.UriSpec head()
WebClient.UriSpec post()
WebClient.UriSpec put()
WebClient.UriSpec patch()
WebClient.UriSpec delete()
WebClient.UriSpec options()
WebClient filter(ExchangeFilterFunction filterFunction)
ExchangeFilterFunction
.filterFunction
- the filter to apply to this clientExchangeFilterFunction.apply(ExchangeFunction)
static WebClient create()
WebClient
with no default, shared preferences across
requests such as base URI, default headers, and others.create(String)
static WebClient create(java.lang.String baseUrl)
For example given this initialization:
WebClient client = WebClient.create("http://abc.com/v1");
The base URI is applied to exchanges with a URI template:
// GET http://abc.com/v1/accounts/43 Mono<Account> result = client.get() .uri("/accounts/{id}", 43) .exchange() .then(response -> response.bodyToMono(Account.class));
The base URI is also applied to exchanges with a UriBuilder
:
// GET http://abc.com/v1/accounts?q=12 Flux<Account> result = client.get() .uri(builder -> builder.path("/accounts").queryParam("q", "12").build()) .exchange() .then(response -> response.bodyToFlux(Account.class));
The base URI can be overridden with an absolute URI:
// GET http://xyz.com/path Mono<Account> result = client.get() .uri("http://xyz.com/path") .exchange() .then(response -> response.bodyToMono(Account.class));
The base URI can be partially overridden with a UriBuilder
:
// GET http://abc.com/v2/accounts?q=12 Flux<Account> result = client.get() .uri(builder -> builder.replacePath("/v2/accounts").queryParam("q", "12").build()) .exchange() .then(response -> response.bodyToFlux(Account.class));
baseUrl
- the base URI for all requestsstatic WebClient.Builder builder()
WebClient
builder.