Class ApiClientBuilder

java.lang.Object
io.unitycatalog.client.ApiClientBuilder

public class ApiClientBuilder extends Object
Builder to create configured ApiClient instances for Unity Catalog operations.

Example usage:


 Map<String, String> configMap = ...;
 ApiClient client = ApiClientBuilder.create()
     .uri("http://localhost:8080")
     .tokenProvider(TokenProvider.create(configMap))
     .retryPolicy(JitterDelayRetryPolicy.builder().maxAttempts(5).build())
     .addAppVersion("MyApp", "1.0.0")
     .build();
 
See Also:
  • Method Details

    • create

      public static ApiClientBuilder create()
      Creates a new instance of ApiClientBuilder.
      Returns:
      a new ApiClientBuilder instance
    • uri

      public ApiClientBuilder uri(URI uri)
      Sets the Unity Catalog server URI.

      The base path /api/2.1/unity-catalog will be automatically appended.

      Parameters:
      uri - the Unity Catalog server URI, must not be null
      Returns:
      this builder instance for method chaining
    • uri

      public ApiClientBuilder uri(String uri)
      Sets the Unity Catalog server URI from a string.
      Parameters:
      uri - the Unity Catalog server URI, must not be null
      Returns:
      this builder instance for method chaining
      See Also:
    • tokenProvider

      public ApiClientBuilder tokenProvider(TokenProvider tokenProvider)
      Sets the token provider for authentication.

      The token will be included in the Authorization header as a Bearer token.

      Parameters:
      tokenProvider - the token provider implementation, must not be null
      Returns:
      this builder instance for method chaining
      See Also:
    • addAppVersion

      public ApiClientBuilder addAppVersion(String name, String version)
      Sets application version metadata as name-version pairs.

      Arguments must be provided in alternating name-version order with an even count, e.g., "MyApp1", "0.1.0".

      Parameters:
      name - the application name.
      version - the application version.
      Returns:
      this builder instance for method chaining
      Throws:
      IllegalArgumentException - if any argument is null or empty.
    • retryPolicy

      public ApiClientBuilder retryPolicy(RetryPolicy retryPolicy)
      Sets a custom request retry policy for handling transient failures.

      Defaults to JitterDelayRetryPolicy if not specified.

      Parameters:
      retryPolicy - the retry policy implementation, must not be null
      Returns:
      this builder instance for method chaining
      See Also:
    • addRequestInterceptor

      public ApiClientBuilder addRequestInterceptor(Consumer<HttpRequest.Builder> interceptor)
      Adds a custom request interceptor to modify HTTP requests before they are sent.

      Request interceptors can be used to add custom headers, modify request properties, or perform logging. Multiple interceptors can be added and will be executed in the order they were registered.

      Example usage:

      
       ApiClientBuilder builder = ApiClientBuilder.create()
           .uri("http://localhost:8080")
           .tokenProvider(TokenProvider.create(configMap))
           .addRequestInterceptor(builder -> builder.header("X-Custom-Header", "custom-value"));
       

      Warning: If you call setRequestInterceptor directly on the built ApiClient, it will replace all built-in interceptors from this builder, including the User-Agent and Authorization headers, which may cause authentication to fail. Always use addRequestInterceptor(Consumer) instead to preserve the built-in interceptors.

      Parameters:
      interceptor - a consumer that accepts an HttpRequest.Builder to modify the request, must not be null
      Returns:
      this builder instance for method chaining
    • build

      public ApiClient build()
      Builds and returns a configured ApiClient instance.
      Returns:
      a configured ApiClient instance
      Throws:
      NullPointerException - if uri or tokenProvider is null