Table of Contents

Class DataAPIClient

Namespace
DataStax.AstraDB.DataApi
Assembly
DataStax.AstraDB.DataApi.dll

The main entrypoint into working with the Data API. It sits at the top of the conceptual hierarchy of the SDK. The client can be passed a default token, which can be overridden by a stronger/weaker token when connecting to a Database or Admin instance.

The DataAPIClient, and the related methods for interacting with the database, accepts a set of options that can be used to affect the command execution. These options can be specified at any level in the call hierarchy (Client, Database, Collection, Command, etc.) The most specific defined option (or its default) will be used for each request.

Once you have a DataAPIClient instance, you can use it to get a Database instance. From there you can create or connect to a Collection.

public class DataAPIClient
Inheritance
DataAPIClient
Inherited Members

Constructors

DataAPIClient()

Initializes a new instance of the DataAPIClient class.

When using this constructor, generally a token is provided later, to the GetDatabase(string) or GetAstraDatabasesAdmin(string, GetAstraDatabasesAdminOptions) methods; or to the eventual end commands via a CommandOptions parameter.

public DataAPIClient()

DataAPIClient(CommandOptions)

Initializes a new instance of the DataAPIClient class with a default set of options

When using this constructor, if not passing a token within the options, generally it is provided later, to the GetDatabase(string) or GetAstraDatabasesAdmin(string, GetAstraDatabasesAdminOptions) methods; or to the eventual end commands via a CommandOptions parameter.

public DataAPIClient(CommandOptions options)

Parameters

options CommandOptions

The default options to use for commands executed by this client.

DataAPIClient(string)

Initializes a new instance of the DataAPIClient class with a default authentication token. This token can be overridden when getting a database GetDatabase(string) or admin instance GetAstraDatabasesAdmin(string, GetAstraDatabasesAdminOptions) as well as in the CommandOptions parameter of the commands.

public DataAPIClient(string token)

Parameters

token string

The token to use for authentication.

DataAPIClient(string, CommandOptions, ILogger)

Initializes a new instance of the DataAPIClient class with a default authentication token. When using the default constructor, the token must be provided to the GetDatabase(string) or GetAstraDatabasesAdmin(string, GetAstraDatabasesAdminOptions) methods or the eventual end commands via a CommandOptions parameter.

public DataAPIClient(string token, CommandOptions options, ILogger logger = null)

Parameters

token string

The token to use for authentication.

options CommandOptions

The default options to use for commands executed by this client.

logger ILogger

The logger to use for logging.

Methods

GetAstraDatabasesAdmin(GetAstraDatabasesAdminOptions)

Gets an instance of the AstraDatabasesAdmin class.

Any options explicitly provided will override those on this DataAPIClient.

public AstraDatabasesAdmin GetAstraDatabasesAdmin(GetAstraDatabasesAdminOptions options = null)

Parameters

options GetAstraDatabasesAdminOptions

The options to use for the resulting databases admin.

Returns

AstraDatabasesAdmin

An instance of AstraDatabasesAdmin.

GetAstraDatabasesAdmin(string, GetAstraDatabasesAdminOptions)

Gets an instance of the AstraDatabasesAdmin class.

Any options explicitly provided will override those on this DataAPIClient.

public AstraDatabasesAdmin GetAstraDatabasesAdmin(string token, GetAstraDatabasesAdminOptions options = null)

Parameters

token string

A token with administrative powers, to use for authentication if required. When passed, overrides any token in the 'options' parameter.

options GetAstraDatabasesAdminOptions

The options to use for the resulting databases admin.

Returns

AstraDatabasesAdmin

An instance of AstraDatabasesAdmin.

GetDatabase(string)

Gets an instance of the Database class given the API Endpoint for the database.

The default keyspace will be used. If you need to connect to a different keyspace, use the GetDatabase(string, string, string) overload or set the keyspace on the GetDatabaseOptions parameter and use the GetDatabase(string, GetDatabaseOptions) overload.

public Database GetDatabase(string apiEndpoint)

Parameters

apiEndpoint string

The API endpoint of the database.

Returns

Database

An instance of the Database class.

Examples

var client = new DataAPIClient("token");
var database = client.GetDatabase("https://01234567-89ab-cdef-0123-456789abcdef-us-east1.apps.astra.datastax.com");

GetDatabase(string, GetDatabaseOptions)

Gets an instance of a Database given the API Endpoint and a set of options.

Any options provided in the options parameter will take precedence over the options from the DataAPIClient.

public Database GetDatabase(string apiEndpoint, GetDatabaseOptions options)

Parameters

apiEndpoint string

The API endpoint of the database.

options GetDatabaseOptions

The options to use for the database, optionally including token or keyspace.

Returns

Database

An instance of the Database class.

Examples

var client = new DataAPIClient("token");
var database = client.GetDatabase("https://01234567-89ab-cdef-0123-456789abcdef-us-east1.apps.astra.datastax.com", new DatabaseCommandOptions() { Keyspace = "myKeyspace" });

GetDatabase(string, string, string)

Gets an instance of the Database class given the API Endpoint of the database to connect to, a token to use, and optionally a keyspace. If the keyspace is not provided the default keyspace will be used.

public Database GetDatabase(string apiEndpoint, string token, string keyspace = null)

Parameters

apiEndpoint string

The API endpoint of the database.

token string

The specific token to use for this database connection.

keyspace string

Optional: The keyspace to connect to.

Returns

Database

An instance of the Database class.

Examples

var client = new DataAPIClient();
var database = client.GetDatabase("https://01234567-89ab-cdef-0123-456789abcdef-us-east1.apps.astra.datastax.com", "token", "myKeyspace");

UsernamePasswordTokenProvider(string, string)

Generate a db token given a username and password (generally needed for instances other than Astra DB)

public static string UsernamePasswordTokenProvider(string username, string password)

Parameters

username string
password string

Returns

string