Interface WebClient.RequestHeadersSpec<S extends WebClient.RequestHeadersSpec<S>>
- Type Parameters:
- S- a self reference to the spec type
- All Known Subinterfaces:
- WebClient.RequestBodySpec, WebClient.RequestBodyUriSpec, WebClient.RequestHeadersUriSpec<S>
- Enclosing interface:
- WebClient
- Since:
- 5.0
- Author:
- Rossen Stoyanchev, Arjen Poutsma, Sebastien Deleuze, Brian Clozel
- 
Method SummaryModifier and TypeMethodDescriptionSet the list of acceptable media types, as specified by theAcceptheader.acceptCharset(Charset... acceptableCharsets) Set the list of acceptable charsets, as specified by theAccept-Charsetheader.apiVersion(@Nullable Object version) Set an API version for the request.Set the attribute with the given name to the given value.attributes(Consumer<Map<String, Object>> attributesConsumer) Provides access to every attribute declared so far with the possibility to add, replace, or remove values.Add a cookie with the given name and value.cookies(Consumer<MultiValueMap<String, String>> cookiesConsumer) Provides access to every cookie declared so far with the possibility to add, replace, or remove values.<V> reactor.core.publisher.Flux<V> exchangeToFlux(Function<ClientResponse, ? extends reactor.core.publisher.Flux<V>> responseHandler) An alternative toretrieve()that provides more control via access to theClientResponse.<V> reactor.core.publisher.Mono<V> exchangeToMono(Function<ClientResponse, ? extends reactor.core.publisher.Mono<V>> responseHandler) An alternative toretrieve()that provides more control via access to theClientResponse.Add the given, single header value under the given name.headers(Consumer<HttpHeaders> headersConsumer) Provides access to every header declared so far with the possibility to add, replace, or remove values.httpRequest(Consumer<ClientHttpRequest> requestConsumer) Callback for access to theClientHttpRequestthat in turn provides access to the native request of the underlying HTTP library.ifModifiedSince(ZonedDateTime ifModifiedSince) Set the value of theIf-Modified-Sinceheader.ifNoneMatch(String... ifNoneMatches) Set the values of theIf-None-Matchheader.retrieve()Proceed to declare how to extract the response.
- 
Method Details- 
acceptSet the list of acceptable media types, as specified by theAcceptheader.- Parameters:
- acceptableMediaTypes- the acceptable media types
- Returns:
- this builder
 
- 
acceptCharset
- 
cookie
- 
cookiesProvides access to every cookie declared so far with the possibility to add, replace, or remove values.- Parameters:
- cookiesConsumer- the consumer to provide access to
- Returns:
- this builder
 
- 
ifModifiedSinceSet the value of theIf-Modified-Sinceheader.The date should be specified as the number of milliseconds since January 1, 1970 GMT. - Parameters:
- ifModifiedSince- the new value of the header
- Returns:
- this builder
 
- 
ifNoneMatch
- 
header
- 
headersProvides access to every header declared so far with the possibility to add, replace, or remove values.- Parameters:
- headersConsumer- the consumer to provide access to
- Returns:
- this builder
 
- 
apiVersionSet an API version for the request. The version is inserted into the request through theconfiguredApiVersionInserter.If no version is set, the defaultApiVersionis used, if configured.If nullis passed, then an API version is not inserted irrespective of default version settings.- Parameters:
- version- the API version for the request; this can be a String or some Object that can be formatted the inserter, e.g. through an- ApiVersionFormatter.
- Since:
- 7.0
 
- 
attribute
- 
attributes
- 
httpRequestCallback for access to theClientHttpRequestthat in turn provides access to the native request of the underlying HTTP library. This could be useful for setting advanced, per-request options that exposed by the underlying library.- Parameters:
- requestConsumer- a consumer to access the- ClientHttpRequestwith
- Returns:
- ResponseSpecto specify how to decode the body
- Since:
- 5.3
 
- 
retrieveWebClient.ResponseSpec retrieve()Proceed to declare how to extract the response. For example to extract aResponseEntitywith status, headers, and body:Mono<ResponseEntity<Person>> entityMono = client.get() .uri("/persons/1") .accept(MediaType.APPLICATION_JSON) .retrieve() .toEntity(Person.class);Or if interested only in the body: Mono<Person> entityMono = client.get() .uri("/persons/1") .accept(MediaType.APPLICATION_JSON) .retrieve() .bodyToMono(Person.class);By default, 4xx and 5xx responses result in a WebClientResponseException. To customize error handling, useonStatushandlers.
- 
exchangeToMono<V> reactor.core.publisher.Mono<V> exchangeToMono(Function<ClientResponse, ? extends reactor.core.publisher.Mono<V>> responseHandler) An alternative toretrieve()that provides more control via access to theClientResponse. This can be useful for advanced scenarios, for example to decode the response differently depending on the response status:Mono<Person> entityMono = client.get() .uri("/persons/1") .accept(MediaType.APPLICATION_JSON) .exchangeToMono(response -> { if (response.statusCode().equals(HttpStatus.OK)) { return response.bodyToMono(Person.class); } else { return response.createError(); } });Note: After the returned Monocompletes, the response body is automatically released if it hasn't been consumed. If the response content is needed, the provided function must declare how to decode it.- Type Parameters:
- V- the type of Object the response will be transformed to
- Parameters:
- responseHandler- the function to handle the response with
- Returns:
- a Monoproduced from the response
- Since:
- 5.3
 
- 
exchangeToFlux<V> reactor.core.publisher.Flux<V> exchangeToFlux(Function<ClientResponse, ? extends reactor.core.publisher.Flux<V>> responseHandler) An alternative toretrieve()that provides more control via access to theClientResponse. This can be useful for advanced scenarios, for example to decode the response differently depending on the response status:Flux<Person> entityMono = client.get() .uri("/persons") .accept(MediaType.APPLICATION_JSON) .exchangeToFlux(response -> { if (response.statusCode().equals(HttpStatus.OK)) { return response.bodyToFlux(Person.class); } else { return response.createError().flux(); } });Note: After the returned Fluxcompletes, the response body is automatically released if it hasn't been consumed. If the response content is needed, the provided function must declare how to decode it.- Type Parameters:
- V- the type of Objects the response will be transformed to
- Parameters:
- responseHandler- the function to handle the response with
- Returns:
- a Fluxof Objects produced from the response
- Since:
- 5.3
 
 
-