public 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(Charset... acceptableCharsets)
Set the list of acceptable charsets, as specified
by the
Accept-Charset header. |
S |
attribute(String name,
Object value)
Set the attribute with the given name to the given value.
|
S |
attributes(Consumer<Map<String,Object>> attributesConsumer)
Manipulate the request attributes with the given consumer.
|
S |
cookie(String name,
String value)
Add a cookie with the given name and value.
|
S |
cookies(Consumer<MultiValueMap<String,String>> cookiesConsumer)
Manipulate the request's cookies with the given consumer.
|
reactor.core.publisher.Mono<ClientResponse> |
exchange()
Exchange the request for a
ClientResponse with full access
to the response status and headers before extracting the body. |
S |
header(String headerName,
String... headerValues)
Add the given, single header value under the given name.
|
S |
headers(Consumer<HttpHeaders> headersConsumer)
Manipulate the request's headers with the given consumer.
|
S |
ifModifiedSince(ZonedDateTime ifModifiedSince)
Set the value of the
If-Modified-Since header. |
S |
ifNoneMatch(String... ifNoneMatches)
Set the values of the
If-None-Match header. |
WebClient.ResponseSpec |
retrieve()
A variant of
exchange() that provides the shortest path to
retrieving the full response (i.e. |
S accept(MediaType... acceptableMediaTypes)
Accept
header.acceptableMediaTypes
- the acceptable media typesS acceptCharset(Charset... acceptableCharsets)
Accept-Charset
header.acceptableCharsets
- the acceptable charsetsS cookie(String name, String value)
name
- the cookie namevalue
- the cookie valueS cookies(Consumer<MultiValueMap<String,String>> cookiesConsumer)
MultiValueMap
methods.cookiesConsumer
- a function that consumes the cookies mapS ifModifiedSince(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(String... ifNoneMatches)
If-None-Match
header.ifNoneMatches
- the new value of the headerS header(String headerName, String... headerValues)
headerName
- the header nameheaderValues
- the header value(s)S headers(Consumer<HttpHeaders> headersConsumer)
HttpHeaders
methods.headersConsumer
- a function that consumes the HttpHeaders
S attribute(String name, Object value)
name
- the name of the attribute to addvalue
- the value of the attribute to addS attributes(Consumer<Map<String,Object>> attributesConsumer)
attributesConsumer
- a function that consumes the attributesreactor.core.publisher.Mono<ClientResponse> exchange()
ClientResponse
with full access
to the response status and headers before extracting the body.
Use Mono.flatMap(Function)
or
Mono.flatMapMany(Function)
to compose further on the response:
Mono<Pojo> mono = client.get().uri("/") .accept(MediaType.APPLICATION_JSON) .exchange() .flatMap(response -> response.bodyToMono(Pojo.class)); Flux<Pojo> flux = client.get().uri("/") .accept(MediaType.APPLICATION_STREAM_JSON) .exchange() .flatMapMany(response -> response.bodyToFlux(Pojo.class));
The response body should always be consumed with bodyTo*
or toEntity*
methods; if you do not care about the body,
you can use bodyToMono(Void.class)
.
Not consuming the response body might lead to HTTP connection pool inconsistencies or memory leaks.
Mono
with the responseretrieve()
WebClient.ResponseSpec retrieve()
exchange()
that provides the shortest path to
retrieving the full response (i.e. status, headers, and body) where
instead of returning Mono<ClientResponse>
it exposes shortcut
methods to extract the response body.
Use of this method is simpler when you don't need to deal directly
with ClientResponse
, e.g. to use a custom BodyExtractor
or to check the status and headers before extracting the response.
Mono<Pojo> bodyMono = client.get().uri("/") .accept(MediaType.APPLICATION_JSON) .retrieve() .bodyToMono(Pojo.class);