-
Notifications
You must be signed in to change notification settings - Fork 924
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide a way to fluently convert an response with
WebClient
and ad…
…d `BlockingWebClient` (#4021) Motivation: - Improved usability - REST API uses a unary call(non-streaming request and response) to send and respond to a message. As `WebClient` supports streaming requests and responses by default, users need to manually aggregate the returned `HttpResponse`. - Testing code needs to wait for the result with `.join()` or `.get()` to assert the result. If we provide `BlockingWebClient`, users and dev can remove a lot of boilerplate code. - Possibility of performance optimization - If a request and response type are known before sending a call, we can optimize the performance for non-streaming calls. - `ExchangeType` introduced in #3956 will be also used at the client side. Modifications: - Add `ResponseAs<T, U>` that defines a way to convert a response into another. - Decoders for `byte[]`, `String`, JSON, `File` are provided by default. - Add `TransformingRequestPreparation<T, R>` that fluently transforms a returns response. - Add `FutureTransformingRequestPreparation` that is a specialized converter for `CompletableFuture`. - Scala's `Future` will be supported via `ScalaResponseAs`. - Add `BlockingWebClient` that returns `AggregatedHttpResponse` by default. - Add `InvalidHttpResponseException` for notifying a failure of JSON decoding. - Introduce `{Request,Response}Entity<T>` for express a decoded type of an HTTP content. - Migrate some tests code for proof of concept. Result: - You can now fluently convert a response using `WebClient`. ```java WebClient client = WebClient.of("api.example.com"); CompletableFuture<ResponseEntity<MyObject>> response = client.prepare() .get("/v1/items/1") .asJson(MyObject.class) .execute(); ``` - You can now use `BlockingWebClient` to wait for a response to be completed. ```java BlockingWebClient client = BlockingWebClient.of("https://api.example.com"); ResponseEntity<MyObject> response = client.prepare() .get("/v1/items/1") .asJson(MyObject.class) .execute(); ```
- Loading branch information
Showing
76 changed files
with
4,671 additions
and
781 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.