Interface RestClient.ResponseSpec
- Enclosing interface:
RestClient
public static interface RestClient.ResponseSpec
Contract for specifying response operations following the exchange.
- Since:
- 6.1
- Author:
- Arjen Poutsma, Sebastien Deleuze
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescription<T> @Nullable TExtract the body as an object of the given type.<T> @Nullable Tbody(ParameterizedTypeReference<T> bodyType) Extract the body as an object of the given type.Set the hint with the given name to the given value forSmartHttpMessageConverters supporting them.onStatus(Predicate<HttpStatusCode> statusPredicate, RestClient.ResponseSpec.ErrorHandler errorHandler) Provide a function to map specific error status codes to an error handler.onStatus(ResponseErrorHandler errorHandler) Provide a function to map specific error status codes to an error handler.Return aResponseEntitywithout a body.<T> ResponseEntity<T> Return aResponseEntitywith the body decoded to an Object of the given type.<T> ResponseEntity<T> toEntity(ParameterizedTypeReference<T> bodyType) Return aResponseEntitywith the body decoded to an Object of the given type.
-
Method Details
-
onStatus
RestClient.ResponseSpec onStatus(Predicate<HttpStatusCode> statusPredicate, RestClient.ResponseSpec.ErrorHandler errorHandler) Provide a function to map specific error status codes to an error handler.By default, if there are no matching status handlers, responses with status codes >= 400 wil throw a
RestClientResponseException.Note that
IOExceptions,UncheckedIOExceptions, andHttpMessageNotReadableExceptionsthrown fromerrorHandlerwill be wrapped in aRestClientException.- Parameters:
statusPredicate- to match responses witherrorHandler- handler that typically, though not necessarily, throws an exception- Returns:
- this builder
-
onStatus
Provide a function to map specific error status codes to an error handler.By default, if there are no matching status handlers, responses with status codes >= 400 wil throw a
RestClientResponseException.Note that
IOExceptions,UncheckedIOExceptions, andHttpMessageNotReadableExceptionsthrown fromerrorHandlerwill be wrapped in aRestClientException.- Parameters:
errorHandler- the error handler- Returns:
- this builder
-
body
Extract the body as an object of the given type.- Type Parameters:
T- the body type- Parameters:
bodyType- the type of return value- Returns:
- the body, or
nullif no response body was available - Throws:
RestClientResponseException- by default when receiving a response with a status code of 4xx or 5xx. UseonStatus(Predicate, ErrorHandler)to customize error response handling.
-
body
Extract the body as an object of the given type.- Type Parameters:
T- the body type- Parameters:
bodyType- the type of return value- Returns:
- the body, or
nullif no response body was available - Throws:
RestClientResponseException- by default when receiving a response with a status code of 4xx or 5xx. UseonStatus(Predicate, ErrorHandler)to customize error response handling.
-
toEntity
Return aResponseEntitywith the body decoded to an Object of the given type.- Type Parameters:
T- response body type- Parameters:
bodyType- the expected response body type- Returns:
- the
ResponseEntitywith the decoded body - Throws:
RestClientResponseException- by default when receiving a response with a status code of 4xx or 5xx. UseonStatus(Predicate, ErrorHandler)to customize error response handling.
-
toEntity
Return aResponseEntitywith the body decoded to an Object of the given type.- Type Parameters:
T- response body type- Parameters:
bodyType- the expected response body type- Returns:
- the
ResponseEntitywith the decoded body - Throws:
RestClientResponseException- by default when receiving a response with a status code of 4xx or 5xx. UseonStatus(Predicate, ErrorHandler)to customize error response handling.
-
toBodilessEntity
ResponseEntity<Void> toBodilessEntity()Return aResponseEntitywithout a body.- Returns:
- the
ResponseEntity - Throws:
RestClientResponseException- by default when receiving a response with a status code of 4xx or 5xx. UseonStatus(Predicate, ErrorHandler)to customize error response handling.
-
hint
Set the hint with the given name to the given value forSmartHttpMessageConverters supporting them.- Parameters:
key- the key of the hint to addvalue- the value of the hint to add- Returns:
- this builder
- Since:
- 7.0
-