org.springframework.web.reactive.function.client

## Interface WebClient.RequestBodySpec

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

      public static interface WebClient.RequestBodySpec
      extends WebClient.RequestHeadersSpec<WebClient.RequestBodySpec>

  Contract for specifying request headers and body leading up to the exchange.

- - ### Method Summary

    All Methods Instance Methods Abstract Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `WebClient.RequestHeadersSpec<?>` | `body(BodyInserter<?,? super ClientHttpRequest> inserter)` Set the body of the request using the given body inserter.
    `WebClient.RequestHeadersSpec<?>` | `body(Object producer, Class<?> elementClass)` Variant of `body(Publisher, Class)` that allows using any producer that can be resolved to `Publisher` via `ReactiveAdapterRegistry`.
    `WebClient.RequestHeadersSpec<?>` | `body(Object producer, ParameterizedTypeReference<?> elementTypeRef)` Variant of `body(Publisher, ParameterizedTypeReference)` that allows using any producer that can be resolved to `Publisher` via `ReactiveAdapterRegistry`.
    `<T,P extends Publisher<T>> WebClient.RequestHeadersSpec<?>` | `body(P publisher, Class<T> elementClass)` Shortcut for `body(BodyInserter)` with a Publisher inserter.
    `<T,P extends Publisher<T>> WebClient.RequestHeadersSpec<?>` | `body(P publisher, ParameterizedTypeReference<T> elementTypeRef)` Variant of `body(Publisher, Class)` that allows providing element type information with generics.
    `WebClient.RequestHeadersSpec<?>` | `bodyValue(Object body)` Shortcut for `body(BodyInserter)` with a value inserter.
    `WebClient.RequestBodySpec` | `contentLength(long contentLength)` Set the length of the body in bytes, as specified by the `Content-Length` header.
    `WebClient.RequestBodySpec` | `contentType(MediaType contentType)` Set the media type of the body, as specified by the `Content-Type` header.
    `WebClient.RequestHeadersSpec<?>` | `syncBody(Object body)` Deprecated. as of Spring Framework 5.2 in favor of `bodyValue(Object)`

    - ### Methods inherited from interface org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec

      `accept, acceptCharset, attribute, attributes, context, cookie, cookies, exchange, exchangeToFlux, exchangeToMono, header, headers, httpRequest, ifModifiedSince, ifNoneMatch, retrieve`

- - ### Method Detail

    - #### contentLength

          WebClient.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:
        `HttpHeaders.setContentLength(long)`

    - #### contentType

          WebClient.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:
        `HttpHeaders.setContentType(MediaType)`

    - #### bodyValue

          WebClient.RequestHeadersSpec<?> bodyValue(Object body)

      Shortcut for `body(BodyInserter)` with a value inserter. For example:

           Person person = ... ;

           Mono<Void> result = client.post()
               .uri("/persons/{id}", id)
               .contentType(MediaType.APPLICATION_JSON)
               .bodyValue(person)
               .retrieve()
               .bodyToMono(Void.class);

      For multipart requests consider providing `MultiValueMap` prepared with `MultipartBodyBuilder`.

      Parameters:
        `body` - the value to write to the request body
      Returns:
        this builder
      Throws:
        `IllegalArgumentException` - if `body` is a `Publisher` or producer known to `ReactiveAdapterRegistry`
      Since:
        5.2

    - #### body

          <T,P extends Publisher<T>> WebClient.RequestHeadersSpec<?> body(P publisher,
                                                                          Class<T> elementClass)

      Shortcut for `body(BodyInserter)` with a Publisher inserter. For example:

           Mono<Person> personMono = ... ;

           Mono<Void> result = client.post()
               .uri("/persons/{id}", id)
               .contentType(MediaType.APPLICATION_JSON)
               .body(personMono, Person.class)
               .retrieve()
               .bodyToMono(Void.class);

      Type Parameters:
        `T` - the type of the elements contained in the publisher
        `P` - the type of the `Publisher`
      Parameters:
        `publisher` - the `Publisher` to write to the request
        `elementClass` - the type of elements published
      Returns:
        this builder

    - #### body

          <T,P extends Publisher<T>> WebClient.RequestHeadersSpec<?> body(P publisher,
                                                                          ParameterizedTypeReference<T> elementTypeRef)

      Variant of `body(Publisher, Class)` that allows providing element type information with generics.
      Type Parameters:
        `T` - the type of the elements contained in the publisher
        `P` - the type of the `Publisher`
      Parameters:
        `publisher` - the `Publisher` to write to the request
        `elementTypeRef` - the type of elements published
      Returns:
        this builder

    - #### body

          WebClient.RequestHeadersSpec<?> body(Object producer,
                                               Class<?> elementClass)

      Variant of `body(Publisher, Class)` that allows using any producer that can be resolved to `Publisher` via `ReactiveAdapterRegistry`.
      Parameters:
        `producer` - the producer to write to the request
        `elementClass` - the type of elements produced
      Returns:
        this builder
      Since:
        5.2

    - #### body

          WebClient.RequestHeadersSpec<?> body(Object producer,
                                               ParameterizedTypeReference<?> elementTypeRef)

      Variant of `body(Publisher, ParameterizedTypeReference)` that allows using any producer that can be resolved to `Publisher` via `ReactiveAdapterRegistry`.
      Parameters:
        `producer` - the producer to write to the request
        `elementTypeRef` - the type of elements produced
      Returns:
        this builder
      Since:
        5.2

    - #### body

          WebClient.RequestHeadersSpec<?> body(BodyInserter<?,? super ClientHttpRequest> inserter)

      Set the body of the request using the given body inserter. See `BodyInserters` for built-in `BodyInserter` implementations.
      Parameters:
        `inserter` - the body inserter to use for the request body
      Returns:
        this builder
      See Also:
        `BodyInserters`

    - #### syncBody

          @Deprecated
          WebClient.RequestHeadersSpec<?> syncBody(Object body)

      Deprecated. as of Spring Framework 5.2 in favor of `bodyValue(Object)`
      Shortcut for `body(BodyInserter)` with a value inserter. As of 5.2 this method delegates to `bodyValue(Object)`.