Package io.avaje.http.client
Interface HttpClientResponse
-
public interface HttpClientResponse
Controls how the response is processed including potential conversion into beans.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description HttpResponse<byte[]>
asByteArray()
Return the content as byte array.HttpResponse<Void>
asDiscarding()
Return the response discarding the response content.HttpResponse<Path>
asFile(Path file)
Return the content into the given file.HttpResponse<InputStream>
asInputStream()
Return the content as InputStream.HttpResponse<Stream<String>>
asLines()
Return the content as a stream of string lines.HttpResponse<String>
asString()
Return the content as string.HttpResponse<Void>
asVoid()
Return the response with check for 200 range status code.<T> T
bean(Class<T> type)
Return the response as a single bean.<T> List<T>
list(Class<T> type)
Return the response as a list of beans.<T> T
read(BodyReader<T> reader)
Returning the response using the given response reader.<T> HttpResponse<T>
withResponseHandler(HttpResponse.BodyHandler<T> responseHandler)
Return the response using the given response body handler.
-
-
-
Method Detail
-
read
<T> T read(BodyReader<T> reader)
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
-
bean
<T> T bean(Class<T> type)
Return the response as a single bean.- 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
<T> List<T> list(Class<T> type)
Return the response as a list of beans.- 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
-
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
-
asString
HttpResponse<String> asString()
Return the content as string.
-
asDiscarding
HttpResponse<Void> asDiscarding()
Return the response discarding the response content.
-
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
HttpResponse<Path> asFile(Path file)
Return the content into the given file.
-
withResponseHandler
<T> HttpResponse<T> withResponseHandler(HttpResponse.BodyHandler<T> responseHandler)
Return the response using the given response body handler.
-
-