Skip to content

Commit

Permalink
Update reference doc after WebClient changes
Browse files Browse the repository at this point in the history
Issue: SPR-14827
  • Loading branch information
bclozel committed Oct 20, 2016
1 parent 59e4326 commit 31af678
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions src/asciidoc/web-reactive.adoc
Expand Up @@ -115,38 +115,29 @@ implies a synchronous, non-blocking controller method.

Spring Framework 5 adds a new reactive `WebClient` in addition to the existing `RestTemplate`.

Each supported HTTP client (e.g. Reactor Netty) is adapted to a set of shared,
A `WebClient` instance use a `ClientHttpConnector` implementation to drive the underlying
supported HTTP client (e.g. Reactor Netty). This client is adapted to a set of shared,
reactive `ClientHttpRequest` and `ClientHttpResponse` abstractions that expose the request
and response body as `Flux<DataBuffer>` with full backpressure support on the read and
the write side. The `Encoder` and `Decoder` abstractions from `spring-core` are also used on
the write side. The `HttpMessageReader` and `HttpMessageWriter` abstractions are also used on
the client side for the serialization of a `Flux` of bytes to and from typed objects.

An example of using the `WebClient`:

[source,java,indent=0]
[subs="verbatim,quotes"]
----
ClientHttpConnector httpConnector = new ReactorClientHttpConnector();
WebClient webClient = new WebClient(httpConnector);
// create an immutable instance of WebClient
WebClient webClient = WebClient.create(new ReactorClientHttpConnector());
Mono<Account> response = webClient
.perform(get("http://example.com/accounts/1").accept(APPLICATION_JSON))
.extract(body(Account.class));
----

The above assumes static method imports from `ClientWebRequestBuilders` and `ResponseExtractors`
that enable a fluent syntax. The same can also be done with RxJava using static imports from
`RxJava1ClientWebRequestBuilder` and `RxJava1ResponseExtractors` instead:
ClientRequest<Void> request = ClientRequest.GET("http://example.com/accounts/{id}", 1L)
.accept(MediaType.APPLICATION_JSON).build();
[source,java,indent=0]
[subs="verbatim,quotes"]
----
Single<Account> response = webClient
.perform(get("http://example.com/accounts/1").accept(APPLICATION_JSON))
.extract(body(Account.class));
Mono<Account> account = this.webClient
.exchange(request)
.then(response -> response.body(toMono(Account.class)));

This comment has been minimized.

Copy link
@poutsma

poutsma Oct 20, 2016

Contributor

You could even change this to bodyToMono(Account.class), as of fa9cc1e.

----


[[web-reactive-getting-started]]
== Getting Started

Expand Down

0 comments on commit 31af678

Please sign in to comment.