Top Description Methods
org.springframework.web.reactive.function.client

public Interface ExchangeFunction

Known Direct Implementers
org.springframework.web.reactive.function.client.ExchangeFunctions.DefaultExchangeFunction
Annotations
@FunctionalInterface
Imports
reactor.core.publisher.Mono

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));
Author
Arjen Poutsma
Since
5.0

Method Summary

Modifier and TypeMethod and Description
public Mono<ClientResponse>

Returns:

the delayed response
exchange
(ClientRequest
the request to exchange
request
)

Exchange the given request for a ClientResponse promise.

public default ExchangeFunction

Returns:

the filtered exchange
filter
(ExchangeFilterFunction
the filter to apply to this exchange
filter
)

Filter the exchange function with the given ExchangeFilterFunction, resulting in a filtered ExchangeFunction.

Method Detail

exchangeback to summary
public Mono<ClientResponse> exchange(ClientRequest request)

Exchange the given request for a ClientResponse 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 the WebClient. Please see the reference documentation for more details on this.

Parameters
request:ClientRequest

the request to exchange

Returns:Mono<ClientResponse>

the delayed response

filterback to summary
public default ExchangeFunction filter(ExchangeFilterFunction filter)

Filter the exchange function with the given ExchangeFilterFunction, resulting in a filtered ExchangeFunction.

Parameters
filter:ExchangeFilterFunction

the filter to apply to this exchange

Returns:ExchangeFunction

the filtered exchange

See Also
ExchangeFilterFunction#apply(ExchangeFunction)