Package kong.unirest.core
Interface HttpResponse<T>
- Type Parameters:
T
- a Http Response holding a specific type of body.
- All Known Implementing Classes:
BaseResponse
,BasicResponse
,ByteResponse
,FailedResponse
,FileResponse
,JsonResponse
,MockResponse
,ObjectResponse
,StringResponse
public interface HttpResponse<T>
-
Method Summary
Modifier and TypeMethodDescriptiongetBody()
return a cookie collection parse from the set-cookie headerIf the transformation to the body failed by an exception it will be kept hereint
<E> HttpResponse
<T> ifFailure
(Class<? extends E> errorClass, Consumer<HttpResponse<E>> consumer) If the response was NOT a 200-series response or a mapping exception happened.ifFailure
(Consumer<HttpResponse<T>> consumer) If the response was NOT a 200-series response or a mapping exception happened.ifSuccess
(Consumer<HttpResponse<T>> consumer) If the response was a 200-series response.boolean
<V> HttpResponse
<V> Map the Response into another response with a different body<V> V
Map the body into another type<E> E
Map the body into a error class if the response was NOT a 200-series response or a mapping exception happened.
-
Method Details
-
getStatus
int getStatus()- Returns:
- the HTTP status code.
-
getStatusText
String getStatusText()- Returns:
- status text
-
getHeaders
Headers getHeaders()- Returns:
- Response Headers (map) with same case as server response.
For instance use
getHeaders().getFirst("Location")
and notgetHeaders().getFirst("location")
to get first header "Location"
-
getBody
T getBody()- Returns:
- the body
-
getParsingError
Optional<UnirestParsingException> getParsingError()If the transformation to the body failed by an exception it will be kept here- Returns:
- a possible RuntimeException. Checked exceptions are wrapped in a UnirestException
-
mapBody
Map the body into another type- Type Parameters:
V
- The return type of the function- Parameters:
func
- a function to transform a body type to something else.- Returns:
- the return type
-
map
Map the Response into another response with a different body- Type Parameters:
V
- The return type of the function- Parameters:
func
- a function to transform a body type to something else.- Returns:
- the return type
-
ifSuccess
If the response was a 200-series response. Invoke this consumer can be chained with ifFailure- Parameters:
consumer
- a function to consume a HttpResponse- Returns:
- the same response
-
ifFailure
If the response was NOT a 200-series response or a mapping exception happened. Invoke this consumer can be chained with ifSuccess- Parameters:
consumer
- a function to consume a HttpResponse- Returns:
- the same response
-
ifFailure
If the response was NOT a 200-series response or a mapping exception happened. map the original body into a error type and invoke this consumer can be chained with ifSuccess- Type Parameters:
E
- the type of error class to map the body- Parameters:
errorClass
- the class of the error type to map toconsumer
- a function to consume a HttpResponse- Returns:
- the same response
-
isSuccess
boolean isSuccess()- Returns:
- true if the response was a 200-series response and no mapping exception happened, else false
-
mapError
Map the body into a error class if the response was NOT a 200-series response or a mapping exception happened. Uses the system Object Mapper- Type Parameters:
E
- the response type- Parameters:
errorClass
- the class for the error- Returns:
- the error object
-
getCookies
Cookies getCookies()return a cookie collection parse from the set-cookie header- Returns:
- a Cookies collection
-
getRequestSummary
HttpRequestSummary getRequestSummary()- Returns:
- a Summary of the HttpRequest that created this response
-