Class DataAPIClients

java.lang.Object
com.datastax.astra.client.DataAPIClients

public class DataAPIClients extends Object
Provides utility methods for initializing and configuring clients to interact with the Data API. This class simplifies the creation of Data API clients by abstracting the complexities associated with configuring clients for different environments and settings.

Depending on the application's requirements and the operational environment, DataAPIClients can tailor the Data API client with appropriate configuration options such as authentication credentials, connection timeouts, proxy settings, and more. This enables developers to quickly and easily set up their Data API clients without delving into the intricate details of each configuration option.

Example Usage:

 
 // Get you the client for a local deployment of Data API
 DataAPIClient devClient = DataAPIClients.local();

 // Get you the database for a local deployment of Data API
 DataAPIClient devClient = DataAPIClients.astraDev("token");

 // Default target environment Astra Production
 DataAPIClient devClient = DataAPIClients.astra("token");
 
 

Note: This class should be used as a starting point for initializing Data API clients. It is advisable to review the specific configuration options relevant to your use case and adjust them accordingly.

  • Field Details

    • DEFAULT_ENDPOINT_LOCAL

      public static final String DEFAULT_ENDPOINT_LOCAL
      Default Http endpoint for local deployment.
      See Also:
  • Method Details

    • clientCassandra

      public static DataAPIClient clientCassandra()
      Creates and configures a DataAPIClient for interaction with a local instance of DataAPI, a data gateway that facilitates working with Apache Cassandra®. This method is tailored for development and testing workflows, enabling simplified and efficient access to local database resources without the need for extensive configuration.

      The returned DataAPIClient is preconfigured with:

      • An authentication token from UsernamePasswordTokenProvider.
      • A destination set to DataAPIDestination.CASSANDRA.
      • Feature flags for tables enabled.
      • Request logging enabled.
      Returns:
      A fully configured DataAPIClient ready for interacting with the local DataAPI instance. This client provides a streamlined interface for executing data operations, abstracting away the complexity of direct database interactions.

      Example usage:

       
       DataAPIClient client = DataAPIClients.local();
       
       
    • clientCassandra

      public static DataAPIClient clientCassandra(String username, String password)
      Creates and configures a DataAPIClient for interaction with a local instance of DataAPI, a data gateway that facilitates working with Apache Cassandra®. This method is tailored for development and testing workflows, enabling simplified and efficient access to local database resources without the need for extensive configuration.

      The returned DataAPIClient is preconfigured with:

      • An authentication token from UsernamePasswordTokenProvider.
      • A destination set to DataAPIDestination.CASSANDRA.
      • Feature flags for tables enabled.
      • Request logging enabled.
      Parameters:
      username - The username for authenticating with the Data API. This username should have the necessary permissions to access the local Data API instance.
      password - The password for authenticating with the Data API. This password should be kept secure and protected from unauthorized access.
      Returns:
      A fully configured DataAPIClient ready for interacting with the local DataAPI instance. This client provides a streamlined interface for executing data operations, abstracting away the complexity of direct database interactions.

      Example usage:

       
       DataAPIClient client = DataAPIClients.local("username", "password");
       
       
    • clientHCD

      public static DataAPIClient clientHCD()
      Creates and configures a DataAPIClient specifically designed for interaction with a local instance of the Data API and Cassandra. This method simplifies the setup process by combining the creation of a DataAPIClient with the integration of a Database abstraction. It is tailored for local development and testing, enabling seamless interaction with Apache Cassandra® through Stargate with minimal configuration.

      Upon creation, this method ensures that a default keyspace is available in the local Stargate instance by automatically invoking DatabaseAdmin.createKeyspace(String). This guarantees that developers have a ready-to-use environment for executing database operations during their development or testing workflows.

      The returned Database client is preconfigured with:

      • A connection to the default local Stargate endpoint.
      • An automatically created keyspace, identified by DEFAULT_KEYSPACE.
      This setup allows developers to focus on application logic rather than database configuration or connectivity.
      Returns:
      A Database client configured for use with a local Stargate instance, including a default keyspace for immediate interaction. This client abstracts database connectivity and administrative tasks, streamlining development workflows.

      Example usage:

       
       Database db = localDbWithDefaultKeyspace();
       
       
    • clientHCD

      public static DataAPIClient clientHCD(String username, String password)
      Creates and configures a DataAPIClient specifically designed for interaction with a local instance of the Data API and Cassandra. This method simplifies the setup process by combining the creation of a DataAPIClient with the integration of a Database abstraction. It is tailored for local development and testing, enabling seamless interaction with Apache Cassandra® through Stargate with minimal configuration.

      Upon creation, this method ensures that a default keyspace is available in the local Stargate instance by automatically invoking DatabaseAdmin.createKeyspace(String). This guarantees that developers have a ready-to-use environment for executing database operations during their development or testing workflows.

      The returned Database client is preconfigured with:

      • A connection to the default local Stargate endpoint.
      • An automatically created keyspace, identified by DEFAULT_KEYSPACE.
      This setup allows developers to focus on application logic rather than database configuration or connectivity.
      Parameters:
      username - The username for authenticating with the Data API. This username should have the necessary
      password - The password for authenticating with the Data API. This password should be kept secure and
      Returns:
      A Database client configured for use with a local Stargate instance, including a default keyspace for immediate interaction. This client abstracts database connectivity and administrative tasks, streamlining development workflows.

      Example usage:

       
       Database db = localDbWithDefaultKeyspace();
       
       
    • localDbWithDefaultKeyspace

      public static Database localDbWithDefaultKeyspace()
      Creates and configures a Database client specifically designed for interaction with a local instance of the Data API and Cassandra. This method simplifies the setup process by combining the creation of a DataAPIClient with the integration of a Database abstraction. It is tailored for local development and testing, enabling seamless interaction with Apache Cassandra® through Stargate with minimal configuration.

      Upon creation, this method ensures that a default keyspace is available in the local Stargate instance by automatically invoking DatabaseAdmin.createKeyspace(String). This guarantees that developers have a ready-to-use environment for executing database operations during their development or testing workflows.

      The returned Database client is preconfigured with:

      • A connection to the default local Stargate endpoint.
      • An automatically created keyspace, identified by DEFAULT_KEYSPACE.
      This setup allows developers to focus on application logic rather than database configuration or connectivity.
      Returns:
      A Database client configured for use with a local Stargate instance, including a default keyspace for immediate interaction. This client abstracts database connectivity and administrative tasks, streamlining development workflows.

      Example usage:

       
       Database db = localDbWithDefaultKeyspace();
       
       
    • astraDev

      public static DataAPIClient astraDev(String token)
      Creates a DataAPIClient configured for interacting with Astra in a development environment. This method simplifies the setup of a client specifically tailored for development purposes, where you might need different configurations or less stringent security measures compared to a production environment. The client is configured to target Astra's development environment, ensuring that operations do not affect production data.
      Parameters:
      token - The authentication token required for accessing Astra's development environment. This token should have the necessary permissions for development activities and be protected accordingly.
      Returns:
      A DataAPIClient instance ready for development activities with Astra, configured with the provided authentication token and targeting Astra's development environment.

      Example usage:

       
       DataAPIClient devClient = DataAPIClients.astraDev("your_astra_dev_token");
       // Utilize devClient for development database operations
       
       
    • astra

      public static DataAPIClient astra(String token)
      Creates a DataAPIClient configured for interacting with Astra in a production environment. This method simplifies the setup of a client specifically tailored for development purposes, where you might need different configurations or less stringent security measures compared to a production environment. The client is configured to target Astra's development environment, ensuring that operations do not affect production data.
      Parameters:
      token - The authentication token required for accessing Astra's development environment. This token should have the necessary permissions for development activities and be protected accordingly.
      Returns:
      A DataAPIClient instance ready for development activities with Astra, configured with the provided authentication token and targeting Astra's development environment.

      Example usage:

       
       DataAPIClient devClient = DataAPIClients.astra("your_astra_dev_token");
       // Utilize devClient for development database operations
       
       
    • astraTest

      public static DataAPIClient astraTest(String token)
      Creates a DataAPIClient specifically configured for interacting with Astra in a test environment. This method is designed for testing scenarios, providing an isolated environment to safely execute database operations without impacting development or production data.

      The returned DataAPIClient is preconfigured to:

      • Authenticate using the provided test-specific token.
      • Target the DataAPIDestination.ASTRA_TEST environment.
      • Enable request logging for better visibility during test operations.
      This setup ensures that all database interactions are restricted to Astra's test environment, preserving the integrity of other environments while facilitating thorough testing.
      Parameters:
      token - The authentication token required for accessing Astra's test environment. It is important to use a token that is explicitly designated for testing purposes to avoid unintended access to production or development resources.
      Returns:
      A DataAPIClient instance configured for testing with Astra, equipped with the provided authentication token and targeting the test environment.

      Example usage:

       
       DataAPIClient testClient = DataAPIClients.astraTest("your_astra_test_token");
       testClient.execute(query -> query.cql("SELECT * FROM test_table").execute());