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.localClient();

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

 // 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

    • createForLocal

      public static DataAPIClient createForLocal()
      Creates and configures a DataAPIClient for interaction with a local instance of Stargate, a data gateway for working with Apache Cassandra®. This method is specifically designed for scenarios where the application is intended to communicate with a Stargate instance running locally, facilitating development and testing workflows by providing easy access to local database resources.
      Returns:
      A fully configured DataAPIClient ready for interacting with the local Stargate instance, equipped with the necessary authentication token and targeting options for Cassandra. This client abstracts away the complexities of direct database communication, providing a simplified interface for data operations.
    • createDefaultLocalDatabase

      public static Database createDefaultLocalDatabase()
      Creates and configures a Database client specifically designed for interaction with a local instance of Stargate. This method streamlines the process of setting up a client for local database interactions, encapsulating both the creation of a DataAPIClient and its integration within a Database abstraction. This setup is ideal for local development and testing, providing a straightforward path to interact with Cassandra through Stargate with minimal setup.
      Returns:
      A Database client ready for use with a local Stargate instance, fully configured for immediate interaction with the database. This client enables developers to focus on their application logic rather than the intricacies of database connectivity and command execution.
    • create

      public static DataAPIClient create(String token)
      Creates a DataAPIClient configured for interaction with Astra, DataStax's cloud-native database as a service. This method streamlines the client setup by requiring only an authentication token, handling the other configuration details internally to ensure compatibility with Astra's API and endpoints.

      By specifying the destination as Astra in the DataAPIOptions, this method ensures that the client is properly configured to communicate with Astra's infrastructure, leveraging the provided token for authentication. This approach enables developers to quickly establish a connection to Astra for database operations without manually setting up connection parameters and authentication details.

      Parameters:
      token - The authentication token required for accessing Astra. This token should be treated securely and not exposed in public code repositories or unsecured locations.
      Returns:
      A DataAPIClient instance ready for use with Astra, fully configured with the provided authentication token and set to target Astra as its destination.

      Example usage:

       
       DataAPIClient astraClient = DataAPIClients.astra("my_astra_auth_token");
       // Use astraClient for database operations
       
       
    • createForAstraDev

      public static DataAPIClient createForAstraDev(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
       
       
    • createForAstraTest

      public static DataAPIClient createForAstraTest(String token)
      Creates a DataAPIClient specifically configured for interacting with Astra in a test environment. This setup is ideal for testing scenarios, where isolation from development and production environments is critical to ensure the integrity and stability of test results. By directing the client to Astra's test environment, it facilitates safe, isolated testing of database interactions without risking the alteration of development or production data.
      Parameters:
      token - The authentication token required for accessing Astra's test environment. Ensure that this token is designated for testing purposes to prevent unintended access to or effects on non-test data and resources.
      Returns:
      A DataAPIClient instance specifically for use in testing scenarios with Astra, equipped with the necessary authentication token and configured to target the test environment.

      Example usage:

       
       DataAPIClient testClient = DataAPIClients.astraTest("your_astra_test_token");
       // Execute test database operations with testClient