Instantiate a client object (TypeScript)
All Data API interactions through a client start with a DataAPIClient object.
Once you have a DataAPIClient object, you can connect to a database and the perform CRUD operations on your data.
Creating a client object is an essential component of Data API client scripts. For more information, see Get started with the Data API (TypeScript).
For more information about the Data API client hierarchy, see Python client internals, TypeScript client internals, Go client internals, Java client internals, and C# client internals.
Result
Returns a DataAPIClient object that you can use to interact with the Data API.
Parameters
| Name | Type | Summary |
|---|---|---|
|
|
Optional.
An application token for a database.
Tokens are prefixed with The token should have sufficient permissions to perform the desired operations.
|
|
Optional.
The options to use for the client, including defaults.
See Properties of |
| Name | Type | Summary |
|---|---|---|
Optional. Specify the environment this client will work in. Can be one of: For more information, see the astra-db-ts README. Default: |
||
Optional. Options related to the API requests made by the client. The
For more information on http clients, see the astra-db-ts README and the client reference. |
||
Optional.
Specify default options for when spawning a |
||
Optional.
Specify default options for when spawning an |
Examples
The following examples demonstrate how to instantiate a client.
Instantiate a client
import { DataAPIClient } from "@datastax/astra-db-ts";
const client = new DataAPIClient();
Instantiate a client and pass a token
import { DataAPIClient } from "@datastax/astra-db-ts";
const client = new DataAPIClient("APPLICATION_TOKEN");
Instantiate a client and specify options
import { DataAPIClient } from "@datastax/astra-db-ts";
import * as fetchH2 from "fetch-h2";
const client = new DataAPIClient({
logging: [
{ events: "commandStarted", emits: "stdout" },
{ events: "commandFailed", emits: "stderr" },
],
httpOptions: { client: "fetch-h2", fetchH2: fetchH2 },
timeoutDefaults: {
requestTimeoutMs: 20000,
generalMethodTimeoutMs: 40000,
},
});
Client reference
For more information, see the client reference.