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(java.nio.charset.Charset... acceptableCharsets)
Set the list of acceptable charsets, as specified
by the
Accept-Charset header. |
S |
cookie(java.lang.String name,
java.lang.String value)
Add a cookie with the given name and value.
|
S |
cookies(MultiValueMap<java.lang.String,java.lang.String> cookies)
Copy the given cookies into the entity's cookies map.
|
<any> |
exchange()
Exchange the request for a
ClientResponse with full access
to the response status and headers before extracting the body. |
S |
header(java.lang.String headerName,
java.lang.String... headerValues)
Add the given, single header value under the given name.
|
S |
headers(HttpHeaders headers)
Copy the given headers into the entity's headers map.
|
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()
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(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(MultiValueMap<java.lang.String,java.lang.String> cookies)
cookies
- the existing cookies to copy fromS 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(HttpHeaders headers)
headers
- the existing headers to copy from<any> 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));
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); Mono<ResponseEntity<Pojo>> entityMono = client.get().uri("/") .accept(MediaType.APPLICATION_JSON) .retrieve() .bodyToEntity(Pojo.class);