Interface HttpClient


public interface HttpClient

An HTTP client is used to create an Endpoint representing an HTTP server and on which client-to-server HTTP exchanges are initiated.

The endpoint(java.net.InetSocketAddress) method creates endpoints bound to a the address of an HTTP server. HTTP client exchanges (request/response) are initiated from the endpoint thus obtained.

The following code show how to send a request to an HTTP server:


 HttpClient httpCLient = ...;
 
 Endpoint endpoint = httpClient.endpoint("example.com". 80).build();
 
 String response = endpoint.exchange(Method.GET, "/")
 	.flatMap(Exchange::response)
 	.flatMapMany(response -> response.body().string().stream())
 	.reduceWith(() -> new StringBuilder(), (acc, chunk) -> acc.append(chunk))
 	.map(StringBuilder::toString)
  .block();
 
 endpoint.close().block();
 
Since:
1.6
Author:
Jeremy Kuhn