Interface WebClient

All Superinterfaces:
HttpClient<HttpClientRequest>, ReleasableResource, RuntimeType.Api<WebClientConfig>
All Known Implementing Classes:
DirectWebClient

public interface WebClient extends RuntimeType.Api<WebClientConfig>, HttpClient<HttpClientRequest>
HTTP client.
  • Method Details

    • builder

      static WebClientConfig.Builder builder()
      Create a new builder of the HTTP protocol, that can be used with any supported version. Which versions are supported is determined by the classpath, HTTP/1.1 is always supported. To support a specific HTTP version only, you can use WebClientConfig.BuilderBase.addProtocolPreference(java.util.List).
      Returns:
      new HTTP client builder
    • create

      static WebClient create()
      Create a new web client with default configuration.
      Returns:
      a new web client
    • create

      static WebClient create(WebClientConfig config)
      Create a new webclient with customized configuration.
      Parameters:
      config - configuration to use
      Returns:
      a new web client
    • create

      static WebClient create(Consumer<WebClientConfig.Builder> consumer)
      Create a new webclient, customizing its configuration.
      Parameters:
      consumer - configuration consumer
      Returns:
      a new web client
    • client

      <T, C extends ProtocolConfig> T client(Protocol<T,C> protocol, C protocolConfig)
      To switch to a non-HTTP protocol client (or a client of a specific HTTP version). The resulting protocol will use this client as a base, so it will share all configuration that is relevant for the protocol.
      Type Parameters:
      T - type of the protocol client
      C - type of the protocol config
      Parameters:
      protocol - protocol instance, usually defined as a constant on the protocol interface
      protocolConfig - configuration of the protocol to be used (if customization is required)
      Returns:
      a new protocol client instance
    • client

      <T, C extends ProtocolConfig> T client(Protocol<T,C> protocol)
      To switch to a non-HTTP protocol client (or a client of a specific HTTP version) using its config configured when creating the client, or default config if none configured. The resulting protocol will use this client as a base, so it will share all configuration that is relevant for the protocol.
      Type Parameters:
      T - type of the protocol client
      C - type of the protocol config
      Parameters:
      protocol - protocol instance, usually defined as a constant on the protocol interface
      Returns:
      a new protocol client instance
    • tcpProtocolIds

      default List<String> tcpProtocolIds()
      Active TCP protocol IDs in preference order. Implementations that do not expose their active protocols return an empty list. The returned list is an immutable snapshot.

      This method must not be called from ClientProtocolProvider.protocol(WebClient, Object) while this client is being constructed. Protocol clients should retain the WebClient instance and obtain the protocol IDs after construction completes.

      Returns:
      unmodifiable list of active TCP protocol IDs
      Throws:
      IllegalStateException - if the protocol inventory is not yet available
    • responseReceived

      default void responseReceived(WebClientProtocolResponse response)
      Notify active HTTP protocol implementations about a transport response received by this client.

      This notification lets one protocol observe response metadata produced by another protocol without creating dependencies between protocol modules. For example, a protocol may use an Alt-Svc response header to discover an alternative service.

      Parameters:
      response - received protocol response
    • executor

      ExecutorService executor()
      Executor services, uses virtual threads.
      Returns:
      executor service
    • cookieManager

      WebClientCookieManager cookieManager()
      Cookie manager to use by this client.
      Returns:
      cookie manager