Interface Exchange<A extends ExchangeContext>

Type Parameters:
A - the type of the exchange context
All Superinterfaces:
BaseExchange<A,Request,Mono<? extends Response>>
All Known Subinterfaces:
UnboundExchange<A>, WebExchange<A>

public interface Exchange<A extends ExchangeContext> extends BaseExchange<A,Request,Mono<? extends Response>>

Represents an HTTP client exchange (request/response) between a client and a server.

An HTTP client exchange is obtained from an Endpoint and allows to build and send an HTTP request or to open a WebSocket to an HTTP server represented by that endpoint.

The HTTP request is only sent when the exchange's response publisher is subscribed and if it hasn't been intercepted by an ExchangeInterceptor which is then responsible for providing the response.


 endpoint.exchange(Method.POST, "/")
 	.flatMap(exchange -> {
		exchange.request()
			.headers(headers -> headers.contentType("text/plain"))
			.body().get().string().value("This is a request body");
		return exchange.response();
   })
  .subscribe(response -> {}); // send the request
 

As for an HTTP request, a WebSocket is only created when the WebSocket exchange publisher is subscribed.


 endpoint.exchange("/")
 	.flatMap(Exchange::webSocket)
  .subscribe(wsExchange -> {}); // create a WebSocket connection
 
Since:
1.6
Author:
Jeremy Kuhn
See Also: