Skip to content

Rest API

Cedrick Lunven edited this page Sep 9, 2021 · 7 revisions

AstraClient and Stargate initializations have been detailed on the Home page. Moving forward the sample code will reuse those classes but do not initialized them.

The Stargate REST API provides CRUD operations on top of Cassandra objects (tables, UDT, records). It was implemented to create an stateless absraction layer on top of Cassandra Query Language (CQL)

Related Api Reference documentation and endpoints can be found there

Class ApiDataClient is the core class to work with Rest DATA. There are multiple ways to retrieve or initialize it.

// Option1. Given an astraClient
ApiDataClient client1 = astraClient.apiStargateData();
ApiDataClient client2 = astraClient.getStargateClient().apiRest();

// Option 2. Given a StargateClient
ApiDataClient client3 = stargateClient.apiRest();

// Option 3. Constructors
ApiDataClient client4_Astra    = new ApiDataClient("http://api_endpoint", "apiToken");
ApiDataClient client5_Stargate = new ApiDataClient("http://api_endpoint", 
  new TokenProviderDefault("username", "password", "http://auth_endpoint");

From now, in another samples, we will use the variable name apiClient as our working instance of ApiDataClient

Working with keyspaces

DataApiIntegrationTest is the main unit test for this API and could be use as reference code

✅. Lists available Keyspace Names

Stream<String> keyspaceNames = apiClient.keyspaceNames();

✅. Lists available Keyspaces

Stream<Keyspace> keyspaces = apiClient.keyspaces();

Schema management

List Collections

Find a collections from its id

CRUD Operations

Search

Paging

Partial update