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 SummaryModifier and TypeMethodDescriptionVariant ofbody(Publisher, Class)that allows using any producer that can be resolved toPublisherviaReactiveAdapterRegistry.body(Object producer, ParameterizedTypeReference<?> elementTypeRef) Variant ofbody(Publisher, ParameterizedTypeReference)that allows using any producer that can be resolved toPublisherviaReactiveAdapterRegistry.body(BodyInserter<?, ? super ClientHttpRequest> inserter) Set the body of the request using the given body inserter.<T,P extends Publisher<T>> 
 WebClient.RequestHeadersSpec<?>Shortcut forbody(BodyInserter)with a Publisher inserter.<T,P extends Publisher<T>> 
 WebClient.RequestHeadersSpec<?>body(P publisher, ParameterizedTypeReference<T> elementTypeRef) Variant ofbody(Publisher, Class)that allows providing element type information with generics.Shortcut forbody(BodyInserter)with a value inserter.<T> WebClient.RequestHeadersSpec<?>bodyValue(T body, ParameterizedTypeReference<T> bodyType) Shortcut forbody(BodyInserter)with a value inserter.contentLength(long contentLength) Set the length of the body in bytes, as specified by theContent-Lengthheader.contentType(MediaType contentType) Set the media type of the body, as specified by theContent-Typeheader.Deprecated.Methods inherited from interface org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpecaccept, acceptCharset, attribute, attributes, context, cookie, cookies, exchange, exchangeToFlux, exchangeToMono, header, headers, httpRequest, ifModifiedSince, ifNoneMatch, retrieve
- 
Method Details- 
contentLengthSet the length of the body in bytes, as specified by theContent-Lengthheader.- Parameters:
- contentLength- the content length
- Returns:
- this builder
- See Also:
 
- 
contentTypeSet the media type of the body, as specified by theContent-Typeheader.- Parameters:
- contentType- the content type
- Returns:
- this builder
- See Also:
 
- 
bodyValueShortcut forbody(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 MultiValueMapprepared withMultipartBodyBuilder.- Parameters:
- body- the value to write to the request body
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- bodyis a- Publisheror producer known to- ReactiveAdapterRegistry
- Since:
- 5.2
- See Also:
 
- 
bodyValueShortcut forbody(BodyInserter)with a value inserter. For example:List<Person> list = ... ; Mono<Void> result = client.post() .uri("/persons/{id}", id) .contentType(MediaType.APPLICATION_JSON) .bodyValue(list, new ParameterizedTypeReference<List<Person>>() {};) .retrieve() .bodyToMono(Void.class);For multipart requests consider providing MultiValueMapprepared withMultipartBodyBuilder.- Type Parameters:
- T- the type of the body
- Parameters:
- body- the value to write to the request body
- bodyType- the type of the body, used to capture the generic type
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- bodyis a- Publisheror producer known to- ReactiveAdapterRegistry
- Since:
- 6.2
 
- 
body<T,P extends Publisher<T>> WebClient.RequestHeadersSpec<?> body(P publisher, Class<T> elementClass) Shortcut forbody(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- Publisherto 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 ofbody(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- Publisherto write to the request
- elementTypeRef- the type of elements published
- Returns:
- this builder
 
- 
bodyVariant ofbody(Publisher, Class)that allows using any producer that can be resolved toPublisherviaReactiveAdapterRegistry.- Parameters:
- producer- the producer to write to the request
- elementClass- the type of elements produced
- Returns:
- this builder
- Since:
- 5.2
 
- 
bodyVariant ofbody(Publisher, ParameterizedTypeReference)that allows using any producer that can be resolved toPublisherviaReactiveAdapterRegistry.- Parameters:
- producer- the producer to write to the request
- elementTypeRef- the type of elements produced
- Returns:
- this builder
- Since:
- 5.2
 
- 
bodySet the body of the request using the given body inserter. SeeBodyInsertersfor built-inBodyInserterimplementations.- Parameters:
- inserter- the body inserter to use for the request body
- Returns:
- this builder
- See Also:
 
- 
syncBodyDeprecated.as of Spring Framework 5.2 in favor ofbodyValue(Object)Shortcut forbody(BodyInserter)with a value inserter. As of 5.2 this method delegates tobodyValue(Object).
 
- 
bodyValue(Object)