Interface ExchangeFunction
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Represents a function that exchanges a request for a (delayed)
ClientResponse. Can be used as an alternative to
WebClient
.
For example:
ExchangeFunction exchangeFunction = ExchangeFunctions.create(new ReactorClientHttpConnector()); URI url = URI.create("https://example.com/resource"); ClientRequest request = ClientRequest.create(HttpMethod.GET, url).build(); Mono<String> bodyMono = exchangeFunction .exchange(request) .flatMap(response -> response.bodyToMono(String.class));
- Since:
- 5.0
- Author:
- Arjen Poutsma
-
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<ClientResponse>
exchange
(ClientRequest request) Exchange the given request for aClientResponse
promise.default ExchangeFunction
filter
(ExchangeFilterFunction filter) Filter the exchange function with the givenExchangeFilterFunction
, resulting in a filteredExchangeFunction
.
-
Method Details
-
exchange
Exchange the given request for aClientResponse
promise.Note: When calling this method from an
ExchangeFilterFunction
that handles the response in some way, extra care must be taken to always consume its content or otherwise propagate it downstream for further handling, for example by theWebClient
. Please see the reference documentation for more details on this.- Parameters:
request
- the request to exchange- Returns:
- the delayed response
-
filter
Filter the exchange function with the givenExchangeFilterFunction
, resulting in a filteredExchangeFunction
.- Parameters:
filter
- the filter to apply to this exchange- Returns:
- the filtered exchange
- See Also:
-