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.RequestBodySpec |
static interface |
WebClient.RequestBodyUriSpec |
static interface |
WebClient.RequestHeadersSpec<S extends WebClient.RequestHeadersSpec<S>>
Contract for specifying request headers leading up to the exchange.
|
static interface |
WebClient.RequestHeadersUriSpec<S extends WebClient.RequestHeadersSpec<S>> |
static interface |
WebClient.ResponseSpec |
static interface |
WebClient.UriSpec<S extends WebClient.RequestHeadersSpec<?>>
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(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.RequestHeadersUriSpec<?> |
delete()
Prepare an HTTP DELETE request.
|
WebClient.RequestHeadersUriSpec<?> |
get()
Prepare an HTTP GET request.
|
WebClient.RequestHeadersUriSpec<?> |
head()
Prepare an HTTP HEAD request.
|
WebClient.RequestBodyUriSpec |
method(HttpMethod method)
Prepare a request for the specified
HttpMethod . |
WebClient.Builder |
mutate()
Return a builder to mutate properties of this web client.
|
WebClient.RequestHeadersUriSpec<?> |
options()
Prepare an HTTP OPTIONS request.
|
WebClient.RequestBodyUriSpec |
patch()
Prepare an HTTP PATCH request.
|
WebClient.RequestBodyUriSpec |
post()
Prepare an HTTP POST request.
|
WebClient.RequestBodyUriSpec |
put()
Prepare an HTTP PUT request.
|
WebClient.RequestHeadersUriSpec<?> get()
WebClient.RequestHeadersUriSpec<?> head()
WebClient.RequestBodyUriSpec post()
WebClient.RequestBodyUriSpec put()
WebClient.RequestBodyUriSpec patch()
WebClient.RequestHeadersUriSpec<?> delete()
WebClient.RequestHeadersUriSpec<?> options()
WebClient.RequestBodyUriSpec method(HttpMethod method)
HttpMethod
.WebClient.Builder mutate()
static WebClient create()
WebClient
with no default, shared preferences across
requests such as base URI, default headers, and others.create(String)
static WebClient create(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.