Interface RestClient.ResponseSpec

Enclosing interface:
RestClient

public static interface RestClient.ResponseSpec
Contract for specifying response operations following the exchange.
  • Method Details

    • 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.

      Parameters:
      statusPredicate - to match responses with
      errorHandler - 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.

      Parameters:
      errorHandler - the error handler
      Returns:
      this builder
    • body

      @Nullable <T> T body(Class<T> bodyType)
      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 null if no response body was available
      Throws:
      RestClientResponseException - by default when receiving a response with a status code of 4xx or 5xx. Use onStatus(Predicate, ErrorHandler) to customize error response handling.
    • body

      @Nullable <T> T body(org.springframework.core.ParameterizedTypeReference<T> bodyType)
      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 null if no response body was available
      Throws:
      RestClientResponseException - by default when receiving a response with a status code of 4xx or 5xx. Use onStatus(Predicate, ErrorHandler) to customize error response handling.
    • toEntity

      <T> ResponseEntity<T> toEntity(Class<T> bodyType)
      Return a ResponseEntity with 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 ResponseEntity with the decoded body
      Throws:
      RestClientResponseException - by default when receiving a response with a status code of 4xx or 5xx. Use onStatus(Predicate, ErrorHandler) to customize error response handling.
    • toEntity

      <T> ResponseEntity<T> toEntity(org.springframework.core.ParameterizedTypeReference<T> bodyType)
      Return a ResponseEntity with 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 ResponseEntity with the decoded body
      Throws:
      RestClientResponseException - by default when receiving a response with a status code of 4xx or 5xx. Use onStatus(Predicate, ErrorHandler) to customize error response handling.
    • toBodilessEntity

      ResponseEntity<Void> toBodilessEntity()
      Return a ResponseEntity without a body.
      Returns:
      the ResponseEntity
      Throws:
      RestClientResponseException - by default when receiving a response with a status code of 4xx or 5xx. Use onStatus(Predicate, ErrorHandler) to customize error response handling.