接口 ExchangeFunction

所有已知实现类:
ExchangeFunctions.DefaultExchangeFunction
函数接口:
这是一个函数接口, 因此可用作 lambda 表达式或方法引用的赋值目标。

@FunctionalInterface public interface ExchangeFunction
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));
 
从以下版本开始:
4.0
作者:
Arjen Poutsma
  • 方法详细资料

    • exchange

      reactor.core.publisher.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.

      参数:
      request - the request to exchange
      返回:
      the delayed response
    • filter

      default ExchangeFunction filter(ExchangeFilterFunction filter)
      Filter the exchange function with the given ExchangeFilterFunction, resulting in a filtered ExchangeFunction.
      参数:
      filter - the filter to apply to this exchange
      返回:
      the filtered exchange
      另请参阅: