New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a way to fluently convert an response with WebClient
and add BlockingWebClient
#4021
Conversation
Motivation: - Improve usability - REST API uses a unary call(non-streaming request and response) to send and respond a message. As `WebClient` supports streaming request and response by default, users need to manually aggregate the returnd `HttpResponse`. - Testing code needs to wait for the result with `.join()` or `.get()`. You can see them many places in test suites. If we provide `BlockingWebClient`, uesrs 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. Modifications: - TBU Result: - You can now fluently convert a response using `WebClient`. ```java WebClient client = WebClient.of("https://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 = WebClient.of("https://api.example.com").blocking(); ResponseEntity<MyObject> response = client.prepare() .get("/v1/items/1") .asJson(MyObject.class) .execute(); ```
Codecov Report
@@ Coverage Diff @@
## master #4021 +/- ##
============================================
- Coverage 73.40% 73.13% -0.27%
- Complexity 15931 16056 +125
============================================
Files 1386 1404 +18
Lines 60869 61433 +564
Branches 7715 7731 +16
============================================
+ Hits 44680 44929 +249
- Misses 12278 12585 +307
- Partials 3911 3919 +8
Continue to review full report at Codecov.
|
.../java/com/linecorp/armeria/server/throttling/bucket4j/TokenBucketThrottlingStrategyTest.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/BlockingWebClient.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/BlockingWebClient.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/BlockingWebClientRequestPreparation.java
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/WebClientRequestPreparation.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/BlockingWebClient.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/BlockingWebClientRequestPreparation.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/BlockingWebClientRequestPreparation.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/BlockingWebClientRequestPreparation.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/FutureTransformingRequestPreparation.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/WebClientRequestPreparation.java
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/WebClientUtil.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/common/NoHttpContentException.java
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/TransformingRequestPreparation.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/WebClientRequestPreparation.java
Show resolved
Hide resolved
core/src/test/java/com/linecorp/armeria/client/BlockingWebClientTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM once the build passes. Great work, @ikhoon 🙇
Oops... 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly nits.
Thanks and great job, @ikhoon!
core/src/main/java/com/linecorp/armeria/client/BlockingWebClient.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/BlockingWebClientRequestPreparation.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/BlockingWebClientRequestPreparation.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/BlockingWebClientRequestPreparation.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/BlockingWebClientRequestPreparation.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/WebClientRequestPreparation.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/common/HttpRequestSetters.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Left some minor nits and questions 🙏
core/src/main/java/com/linecorp/armeria/client/BlockingWebClientRequestPreparation.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/common/RequestEntity.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/FutureTransformingRequestPreparation.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/InvalidHttpResponseException.java
Show resolved
Hide resolved
…ntRequestPreparation.java Co-authored-by: jrhee17 <guins_j@guins.org>
…ers.java Co-authored-by: minux <songmw725@gmail.com>
Can you check the scala test compilation failure? 😅 |
😱😱😱 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @ikhoon ! Looking forward to reviewing the exchangeType
PR as well 🙇 👍 🥇
Motivation:
and respond to a message.
As
WebClient
supports streaming requests and responses by default,users need to manually aggregate the returned
HttpResponse
..join()
or.get()
to assert the result.
If we provide
BlockingWebClient
, users and dev can remove a lot ofboilerplate code.
can optimize the performance for non-streaming calls.
ExchangeType
introduced in Provide a way to enable/disable streaming for a request or response #3956 will be also used at the client side.Modifications:
ResponseAs<T, U>
that defines a way to convert a response into another.byte[]
,String
, JSON,File
are provided by default.TransformingRequestPreparation<T, R>
that fluently transforms a returns response.FutureTransformingRequestPreparation
that is a specialized converter forCompletableFuture
.Future
will be supported viaScalaResponseAs
.BlockingWebClient
that returnsAggregatedHttpResponse
by default.InvalidHttpResponseException
for notifying a failure of JSON decoding.{Request,Response}Entity<T>
for express a decoded type of an HTTP content.Result:
WebClient
.BlockingWebClient
to wait for a response to be completed.