S
- a self reference to the spec typepublic static interface WebClient.RequestHeadersSpec<S extends WebClient.RequestHeadersSpec<S>>
Modifier and Type | Method and Description |
---|---|
S |
accept(MediaType... acceptableMediaTypes)
Set the list of acceptable media types, as
specified by the
Accept header. |
S |
acceptCharset(java.nio.charset.Charset... acceptableCharsets)
Set the list of acceptable charsets, as specified
by the
Accept-Charset header. |
S |
attribute(java.lang.String name,
java.lang.Object value)
Set the attribute with the given name to the given value.
|
S |
attributes(java.util.function.Consumer<java.util.Map<java.lang.String,java.lang.Object>> attributesConsumer)
Provides access to every attribute declared so far with the
possibility to add, replace, or remove values.
|
S |
cookie(java.lang.String name,
java.lang.String value)
Add a cookie with the given name and value.
|
S |
cookies(java.util.function.Consumer<MultiValueMap<java.lang.String,java.lang.String>> cookiesConsumer)
Provides access to every cookie declared so far with the possibility
to add, replace, or remove values.
|
reactor.core.publisher.Mono<ClientResponse> |
exchange()
Perform the HTTP request and return a
ClientResponse with the
response status and headers. |
S |
header(java.lang.String headerName,
java.lang.String... headerValues)
Add the given, single header value under the given name.
|
S |
headers(java.util.function.Consumer<HttpHeaders> headersConsumer)
Provides access to every header declared so far with the possibility
to add, replace, or remove values.
|
S |
ifModifiedSince(java.time.ZonedDateTime ifModifiedSince)
Set the value of the
If-Modified-Since header. |
S |
ifNoneMatch(java.lang.String... ifNoneMatches)
Set the values of the
If-None-Match header. |
WebClient.ResponseSpec |
retrieve()
Perform the HTTP request and retrieve the response body:
|
S accept(MediaType... acceptableMediaTypes)
Accept
header.acceptableMediaTypes
- the acceptable media typesS acceptCharset(java.nio.charset.Charset... acceptableCharsets)
Accept-Charset
header.acceptableCharsets
- the acceptable charsetsS cookie(java.lang.String name, java.lang.String value)
name
- the cookie namevalue
- the cookie valueS cookies(java.util.function.Consumer<MultiValueMap<java.lang.String,java.lang.String>> cookiesConsumer)
cookiesConsumer
- the consumer to provide access toS ifModifiedSince(java.time.ZonedDateTime ifModifiedSince)
If-Modified-Since
header.
The date should be specified as the number of milliseconds since January 1, 1970 GMT.
ifModifiedSince
- the new value of the headerS ifNoneMatch(java.lang.String... ifNoneMatches)
If-None-Match
header.ifNoneMatches
- the new value of the headerS header(java.lang.String headerName, java.lang.String... headerValues)
headerName
- the header nameheaderValues
- the header value(s)S headers(java.util.function.Consumer<HttpHeaders> headersConsumer)
headersConsumer
- the consumer to provide access toS attribute(java.lang.String name, java.lang.Object value)
name
- the name of the attribute to addvalue
- the value of the attribute to addS attributes(java.util.function.Consumer<java.util.Map<java.lang.String,java.lang.Object>> attributesConsumer)
attributesConsumer
- the consumer to provide access toWebClient.ResponseSpec retrieve()
Mono<Person> bodyMono = client.get() .uri("/persons/1") .accept(MediaType.APPLICATION_JSON) .retrieve() .bodyToMono(Person.class);
This method is a shortcut to using exchange()
and
decoding the response body through ClientResponse
.
ResponseSpec
to specify how to decode the bodyexchange()
reactor.core.publisher.Mono<ClientResponse> exchange()
ClientResponse
with the
response status and headers. You can then use methods of the response
to consume the body:
Mono<Person> mono = client.get() .uri("/persons/1") .accept(MediaType.APPLICATION_JSON) .exchange() .flatMap(response -> response.bodyToMono(Person.class)); Flux<Person> flux = client.get() .uri("/persons") .accept(MediaType.APPLICATION_STREAM_JSON) .exchange() .flatMapMany(response -> response.bodyToFlux(Person.class));
NOTE: You must always use one of the body or
entity methods of the response to ensure resources are released.
See ClientResponse
for more details.
Mono
for the responseretrieve()