Interface RestClient.RequestBodySpec

All Superinterfaces:
RestClient.RequestHeadersSpec<RestClient.RequestBodySpec>
All Known Subinterfaces:
RestClient.RequestBodyUriSpec
Enclosing interface:
RestClient

public static interface RestClient.RequestBodySpec extends RestClient.RequestHeadersSpec<RestClient.RequestBodySpec>
Contract for specifying request headers and body leading up to the exchange.
  • Method Details

    • contentLength

      RestClient.RequestBodySpec contentLength(long contentLength)
      Set the length of the body in bytes, as specified by the Content-Length header.
      Parameters:
      contentLength - the content length
      Returns:
      this builder
      See Also:
    • contentType

      RestClient.RequestBodySpec contentType(MediaType contentType)
      Set the media type of the body, as specified by the Content-Type header.
      Parameters:
      contentType - the content type
      Returns:
      this builder
      See Also:
    • body

      Set the body of the request to the given Object. For example:

       Person person = ... ;
       ResponseEntity<Void> response = client.post()
           .uri("/persons/{id}", id)
           .contentType(MediaType.APPLICATION_JSON)
           .body(person)
           .retrieve()
           .toBodilessEntity();
       
      Parameters:
      body - the body of the response
      Returns:
      the built response
    • body

      <T> RestClient.RequestBodySpec body(T body, ParameterizedTypeReference<T> bodyType)
      Set the body of the response to the given Object. The parameter bodyType is used to capture the generic type.
      Parameters:
      body - the body of the response
      bodyType - the type of the body, used to capture the generic type
      Returns:
      the built response
    • body

      Set the body of the response to the given function that writes to an OutputStream.
      Parameters:
      body - a function that takes an OutputStream and can throw an IOException
      Returns:
      the built response