ExchangeFunction.java 2.0 KB
Newer Older
1
/*
2
 * Copyright 2002-2018 the original author or authors.
3 4 5 6 7 8 9 10 11 12 13 14 15 16
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

17
package org.springframework.web.reactive.function.client;
18

19
import reactor.core.publisher.Mono;
20 21

/**
22
 * Represents a function that exchanges a {@linkplain ClientRequest request} for a (delayed)
23
 * {@linkplain ClientResponse}. Can be used as an alternative to {@link WebClient}.
J
Juergen Hoeller 已提交
24
 *
25 26 27
 * <p>For example:
 * <pre class="code">
 * ExchangeFunction exchangeFunction = ExchangeFunctions.create(new ReactorClientHttpConnector());
S
Spring Operator 已提交
28
 * ClientRequest&lt;Void&gt; request = ClientRequest.method(HttpMethod.GET, "https://example.com/resource").build();
29 30
 *
 * Mono&lt;String&gt; result = exchangeFunction
J
Juergen Hoeller 已提交
31 32
 *     .exchange(request)
 *     .then(response -> response.bodyToMono(String.class));
33
 * </pre>
34
 *
35
 * @author Arjen Poutsma
36
 * @since 5.0
37
 */
38 39
@FunctionalInterface
public interface ExchangeFunction {
40

41 42 43
	/**
	 * Exchange the given request for a response mono.
	 * @param request the request to exchange
44
	 * @return the delayed response
45
	 */
46
	Mono<ClientResponse> exchange(ClientRequest request);
47

48 49 50 51 52 53 54 55 56 57 58
	/**
	 * Filters this exchange function with the given {@code ExchangeFilterFunction}, resulting in a
	 * filtered {@code ExchangeFunction}.
	 * @param filter the filter to apply to this exchange
	 * @return the filtered exchange
	 * @see ExchangeFilterFunction#apply(ExchangeFunction)
	 */
	default ExchangeFunction filter(ExchangeFilterFunction filter) {
		return filter.apply(this);
	}

59
}