-
Method Summary
Modifier and TypeMethodDescription<T> HttpResponse
<T> Return the response with the body containing a single instance of the given type.<T> HttpResponse
<T> Return the response with the body containing a single instance of the given type.HttpResponse
<byte[]> Return the content as byte array.Return the response discarding the response content.Return the content into the given file.Return the content as InputStream.asLines()
Return the content as a stream of string lines.<T> HttpResponse
<List<T>> Return the response with the body containing a list of the given type.<T> HttpResponse
<List<T>> Return the response with the body containing a list of the given type.Return the content as string with check for 200 range status code.<T> HttpResponse
<Stream<T>> Return the response with the body containing a stream of beans of the given type.<T> HttpResponse
<Stream<T>> Return the response with the body containing a stream of beans of the given type.asString()
Return the content as string.asVoid()
Return the response with check for 200 range status code.async()
Send the request async using CompletableFuture.<T> T
Return the response as a single bean.<T> T
Return the response as a single bean.call()
Return a HttpCall which allows either sync or async execution of the request.<T> HttpResponse
<T> handler
(HttpResponse.BodyHandler<T> responseHandler) Return the response using the given response body handler.<T> List
<T> Return the response as a list of beans.<T> List
<T> Return the response as a list of beans.<T> T
read
(BodyReader<T> reader) Returning the response using the given response reader.<T> Stream
<T> Return the response as a stream of beans.<T> Stream
<T> Return the response as a stream of beans.
-
Method Details
-
async
HttpAsyncResponse async()Send the request async using CompletableFuture.Example async().bean()
In this example POST async that will return a bean converted from json response.
client.request() ... .POST().async() .bean(HelloDto.class) .whenComplete((helloDto, throwable) -> { if (throwable != null) { HttpException httpException = (HttpException) throwable.getCause(); int statusCode = httpException.statusCode(); // maybe convert json error response body to a bean (using Jackson/Gson) MyErrorBean errorResponse = httpException.bean(MyErrorBean.class); .. } else { // process helloDto ... } });
-
call
HttpCallResponse call()Return a HttpCall which allows either sync or async execution of the request. -
read
Returning the response using the given response reader.- Type Parameters:
T
- The type that the content is converted to.- Parameters:
reader
- The response reader.- Returns:
- The response converted into the appropriate bean via the reader.
- Throws:
HttpException
- when the response has error status codes
-
as
Return the response with the body containing a single instance of the given type.If the HTTP statusCode is not in the 2XX range a HttpException is throw which contains the HttpResponse. This is the cause in the CompletionException when using an async request.
- Type Parameters:
T
- The type that the content is converted to.- Parameters:
type
- The type of the bean to convert the response content into.- Returns:
- The response containing the converted body.
- Throws:
HttpException
- when the response has error status codes
-
as
Return the response with the body containing a single instance of the given type.If the HTTP statusCode is not in the 2XX range a HttpException is throw which contains the HttpResponse. This is the cause in the CompletionException when using an async request.
- Parameters:
type
- The type of the bean to convert the response content into.- Returns:
- The response containing the converted body.
- Throws:
HttpException
- when the response has error status codes
-
asList
Return the response with the body containing a list of the given type.If the HTTP statusCode is not in the 2XX range a HttpException is throw which contains the HttpResponse. This is the cause in the CompletionException when using an async request.
- Type Parameters:
T
- The type that the content is converted to.- Parameters:
type
- The type of the bean to convert the response content into.- Returns:
- The response containing the converted body.
- Throws:
HttpException
- when the response has error status codes
-
asList
Return the response with the body containing a list of the given type.If the HTTP statusCode is not in the 2XX range a HttpException is throw which contains the HttpResponse. This is the cause in the CompletionException when using an async request.
- Type Parameters:
T
- The type that the content is converted to.- Parameters:
type
- The type of the bean to convert the response content into.- Returns:
- The response containing the converted body.
- Throws:
HttpException
- when the response has error status codes
-
asStream
Return the response with the body containing a stream of beans of the given type.Typically the response is expected to be application/x-json-stream newline delimited json payload.
Note that for this stream request the response content is not deemed 'loggable' by avaje-http-client. This is because the entire response may not be available at the time of the callback. As such
RequestLogger
will not include response content when logging stream request/responseIf the HTTP statusCode is not in the 2XX range a HttpException is throw which contains the HttpResponse. This is the cause in the CompletionException when using an async request.
- Type Parameters:
T
- The type that the content is converted to.- Parameters:
type
- The type of the bean to convert the response content into.- Returns:
- The response containing the converted body.
- Throws:
HttpException
- when the response has error status codes
-
asStream
Return the response with the body containing a stream of beans of the given type.Typically the response is expected to be application/x-json-stream newline delimited json payload.
Note that for this stream request the response content is not deemed 'loggable' by avaje-http-client. This is because the entire response may not be available at the time of the callback. As such
RequestLogger
will not include response content when logging stream request/responseIf the HTTP statusCode is not in the 2XX range a HttpException is throw which contains the HttpResponse. This is the cause in the CompletionException when using an async request.
- Type Parameters:
T
- The type that the content is converted to.- Parameters:
type
- The type of the bean to convert the response content into.- Returns:
- The response containing the converted body.
- Throws:
HttpException
- when the response has error status codes
-
bean
Return the response as a single bean.If the HTTP statusCode is not in the 2XX range a HttpException is throw which contains the HttpResponse. This is the cause in the CompletionException when using an async request.
- Type Parameters:
T
- The type that the content is converted to.- Parameters:
type
- The type of the bean to convert the response content into.- Returns:
- The bean the response is converted into.
- Throws:
HttpException
- when the response has error status codes
-
list
Return the response as a list of beans.If the HTTP statusCode is not in the 2XX range a HttpException is throw which contains the HttpResponse. This is the cause in the CompletionException when using an async request.
- Type Parameters:
T
- The type that the content is converted to.- Parameters:
type
- The type of the bean to convert the response content into.- Returns:
- The list of beans the response is converted into.
- Throws:
HttpException
- when the response has error status codes
-
stream
Return the response as a stream of beans.Typically the response is expected to be application/x-json-stream newline delimited json payload.
Note that for this stream request the response content is not deemed 'loggable' by avaje-http-client. This is because the entire response may not be available at the time of the callback. As such
RequestLogger
will not include response content when logging stream request/responseIf the HTTP statusCode is not in the 2XX range a HttpException is throw which contains the HttpResponse. This is the cause in the CompletionException when using an async request.
- Type Parameters:
T
- The type that the content is converted to.- Parameters:
type
- The type of the bean to convert the response content into.- Returns:
- The stream of beans from the response
- Throws:
HttpException
- when the response has error status codes
-
bean
Return the response as a single bean.If the HTTP statusCode is not in the 2XX range a HttpException is throw which contains the HttpResponse. This is the cause in the CompletionException when using an async request.
- Parameters:
type
- The type of the bean to convert the response content into.- Returns:
- The bean the response is converted into.
- Throws:
HttpException
- when the response has error status codes
-
list
Return the response as a list of beans.If the HTTP statusCode is not in the 2XX range a HttpException is throw which contains the HttpResponse. This is the cause in the CompletionException when using an async request.
- Parameters:
type
- The type of the bean to convert the response content into.- Returns:
- The list of beans the response is converted into.
- Throws:
HttpException
- when the response has error status codes
-
stream
Return the response as a stream of beans.Typically the response is expected to be application/x-json-stream newline delimited json payload.
Note that for this stream request the response content is not deemed 'loggable' by avaje-http-client. This is because the entire response may not be available at the time of the callback. As such
RequestLogger
will not include response content when logging stream request/responseIf the HTTP statusCode is not in the 2XX range a HttpException is throw which contains the HttpResponse. This is the cause in the CompletionException when using an async request.
- Parameters:
type
- The type of the bean to convert the response content into.- Returns:
- The stream of beans from the response
- Throws:
HttpException
- when the response has error status codes
-
asVoid
HttpResponse<Void> asVoid()Return the response with check for 200 range status code.Will throw an HttpException if the status code is in the error range allowing the caller to access the error message body via
HttpException.bean(Class)
This is intended to be used for POST, PUT, DELETE requests where the caller is only interested in the response body when an error occurs (status code not in 200 range).
- Throws:
HttpException
- when the response has error status codes
-
asDiscarding
HttpResponse<Void> asDiscarding()Return the response discarding the response content.Unlike
asVoid()
this will discard any response body including any error response body. We should instead useasVoid()
if we might get an error response body that we want to read via for exampleHttpException.bean(Class)
. -
asString
HttpResponse<String> asString()Return the content as string. -
asPlainString
HttpResponse<String> asPlainString()Return the content as string with check for 200 range status code.If the status code is in the error range then a
HttpException
is thrown. -
asInputStream
HttpResponse<InputStream> asInputStream()Return the content as InputStream. -
asLines
HttpResponse<Stream<String>> asLines()Return the content as a stream of string lines. -
asByteArray
HttpResponse<byte[]> asByteArray()Return the content as byte array. -
asFile
Return the content into the given file. -
handler
Return the response using the given response body handler.
-