HttpClient Examples (Async)

  • Asynchronous HTTP exchange

    This example demonstrates a basic asynchronous HTTP request / response exchange. Response content is buffered in memory for simplicity.

  • Asynchronous HTTP exchange with content streaming

    This example demonstrates an asynchronous HTTP request / response exchange with a full content streaming.

  • Pipelined HTTP/1.1 exchanges

    This example demonstrates a pipelined execution of multiple HTTP/1.1 request / response exchanges. Response content is buffered in memory for simplicity.

  • Multiplexed HTTP/2 exchanges

    This example demonstrates a multiplexed execution of multiple HTTP/2 request / response exchanges. Response content is buffered in memory for simplicity.

  • Request execution interceptors

    This example demonstrates how to insert custom request interceptor and an execution interceptor to the request execution chain.

  • Message trailers

    This example demonstrates how to use a custom execution interceptor to add trailers to all outgoing request enclosing an entity..

  • Multiplexed HTTP/2 exchanges

    This example demonstrates handling of HTTP/2 message exchanges pushed by the server.

  • Client authentication

    This example demonstrates execution of an HTTP request against a target site that requires user authentication.

  • Custom SSL context

    This example demonstrates how to create secure connections with a custom SSL context.

  • Connection / TLS configuation per route / host

    This example demonstrates how to use connection configuration on a per-route or a per-host basis.

  • Connection eviction

    This example demonstrates how to evict expired and idle connections from the connection pool.

  • Preemptive BASIC authentication

    This example shows how HttpClient can be customized to authenticate preemptively using BASIC scheme. Generally, preemptive authentication can be considered less secure than a response to an authentication challenge and therefore discouraged.

  • HTTP version negotiation

    This example demonstrates how to make HttpClient negotiate or force a particular version of HTTP protocol during the TLS handshake. Please note that protocol version policy setting also applies to non-HTTPS connections.

  • Virtual HTTPS / SNI

    This example demonstrates how to use SNI to send requests to a virtual HTTPS endpoint using the async I/O.

  • Unix domain sockets

    This example demonstrates how to connect to a local daemon (in this case, the Docker daemon) over a Unix domain socket. Note that this requires Java 17+. On older versions of Java, Unix domain sockets are only supported with classic I/O and require an additional dependency on JUnixSocket.