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));
| 修飾子と型 | インターフェースと説明 |
|---|---|
static interface | WebClient.BuilderWebClient の変更可能なビルダー。 |
static interface | WebClient.RequestBodySpec |
static interface | WebClient.RequestBodyUriSpec |
static interface | WebClient.RequestHeadersSpec<S extends WebClient.RequestHeadersSpec<S>> 交換に至るまでのリクエストヘッダーを指定するための契約。 |
static interface | WebClient.RequestHeadersUriSpec<S extends WebClient.RequestHeadersSpec<S>> |
static interface | WebClient.ResponseSpec |
static interface | WebClient.UriSpec<S extends WebClient.RequestHeadersSpec<?>> リクエストの URI を指定するための契約。 |
| 修飾子と型 | メソッドと説明 |
|---|---|
static WebClient.Builder | builder()WebClient ビルダーを入手します。 |
static WebClient | create() デフォルトのない新しい WebClient を作成し、ベース URI、デフォルトヘッダーなどのリクエスト間で設定を共有します。 |
static WebClient | create(StringSE baseUrl) たとえば、すべてのリクエストで同じホスト、ポート、ベースパス、クエリパラメーターさえ繰り返さないように、クライアントを介して実行されるリクエストのベース URI を設定します。 |
WebClient.RequestHeadersUriSpec<?> | delete()HTTP DELETE リクエストを準備します。 |
WebClient.RequestHeadersUriSpec<?> | get()HTTP GET リクエストを準備します。 |
WebClient.RequestHeadersUriSpec<?> | head()HTTP HEAD リクエストを準備します。 |
WebClient.RequestBodyUriSpec | method(HttpMethod method) 指定された HttpMethod のリクエストを準備します。 |
WebClient.Builder | mutate() この Web クライアントのプロパティを変更するビルダーを返します。 |
WebClient.RequestHeadersUriSpec<?> | options()HTTP OPTIONS リクエストを準備します。 |
WebClient.RequestBodyUriSpec | patch()HTTP PATCH リクエストを準備します。 |
WebClient.RequestBodyUriSpec | post()HTTP POST リクエストを準備します。 |
WebClient.RequestBodyUriSpec | put()HTTP PUT リクエストを準備します。 |
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 を作成し、ベース URI、デフォルトヘッダーなどのリクエスト間で設定を共有します。create(String)static WebClient create(StringSE baseUrl)
たとえば、この初期化を考えると:
WebClient client = WebClient.create("http://abc.com/v1");
ベース URI は、URI テンプレートとの交換に適用されます。
// GET http://abc.com/v1/accounts/43
Mono<Account> result = client.get()
.uri("/accounts/{id}", 43)
.exchange()
.then(response -> response.bodyToMono(Account.class));
ベース URI は、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));
ベース URI は絶対 URI でオーバーライドできます。
// GET http://xyz.com/path
Mono<Account> result = client.get()
.uri("http://xyz.com/path")
.exchange()
.then(response -> response.bodyToMono(Account.class));
ベース URI は、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 - すべてのリクエストのベース URIstatic WebClient.Builder builder()
WebClient ビルダーを入手します。