Illustration Image

Cassandra.Link

The best knowledge base on Apache Cassandra®

Helping platform leaders, architects, engineers, and operators build scalable real time data platforms.

10/23/2020

Reading time:1 min

DataStax-Examples/all_astra_apis

by DataStax-Examples

Data in the Astra DBaaS can be accessed using four different APIs (so far).GraphQL APIREST APICassandra Query Language (CQL) APIMapper APIThis reference project shows how you can use these APIs from Node.js.All Astra APIs tutorial:Contributors: Kiyu GabrielProject LayoutThe most files are in the root of the project:table_multi_api.js: examples of CRUD operations using each APIschema.cql: example Cassandra schema that works with the testsconfig.js: your settingsutility.js: functions to deal with some of the differences in the way the APIs like their dataKeyspaceMapper.js: class that wraps the regular Node.js driver Mapper functionality to create one model per table in the keyspaceTableMapper.js: support file for KeyspaceMapper.jsThere are also test files to illustrate how the examples could be used:test/multi_table_api.js: test the functionality of the table_multi_api.jstest/KeyspaceMapper.js: test the functionality of the KeyspaceMappertest/sample_data.js: sample data for table_multi_api.jsSetup and RunningPrerequisitesThis requires a recent version of Node.js; I was using v14.7You will need to install Mocha npm install mochaYou'll also need an Astra database (can be set up for free)RunningIf you'd like to see the tests in action, you'll need a test database.Create a free-forever Cassandra Database with DataStax Astra: click here to get started 🚀Set up a database, keyspace, username and password (in the samples, I named the database and keyspace "stuff", username "stuff_user" and password "stuff_password")Put all of this information into your config.jsDownload the secure connect bundle from the summary page after your database has launched. You'll need this later. Save this file update the config.js file with the path to it.Also grab the REST API URL from the Summary page - put base of this URL in the config.js. The base of the REST API URL and the GraphQL API URL are the same, just trim off the "/api/rest" part.Use the CQL Console to create the tables defined in the schema.cql fileIn the root of this project, run npm test to exercise all the APIs.

Illustration Image

Data in the Astra DBaaS can be accessed using four different APIs (so far).

  • GraphQL API
  • REST API
  • Cassandra Query Language (CQL) API
  • Mapper API

This reference project shows how you can use these APIs from Node.js.

All Astra APIs tutorial:

Tutorial

Contributors: Kiyu Gabriel

Project Layout

The most files are in the root of the project:

  • table_multi_api.js: examples of CRUD operations using each API
  • schema.cql: example Cassandra schema that works with the tests
  • config.js: your settings
  • utility.js: functions to deal with some of the differences in the way the APIs like their data
  • KeyspaceMapper.js: class that wraps the regular Node.js driver Mapper functionality to create one model per table in the keyspace
  • TableMapper.js: support file for KeyspaceMapper.js

There are also test files to illustrate how the examples could be used:

Setup and Running

Prerequisites

  • This requires a recent version of Node.js; I was using v14.7
  • You will need to install Mocha npm install mocha
  • You'll also need an Astra database (can be set up for free)

Running

If you'd like to see the tests in action, you'll need a test database.

  1. Create a free-forever Cassandra Database with DataStax Astra: click here to get started 🚀90944037-75aa8180-e3d1-11ea-9b17-91929d55bc07
  2. Set up a database, keyspace, username and password (in the samples, I named the database and keyspace "stuff", username "stuff_user" and password "stuff_password")
  3. Put all of this information into your config.js
  4. Download the secure connect bundle from the summary page after your database has launched. You'll need this later. Save this file update the config.js file with the path to it.
  5. Also grab the REST API URL from the Summary page - put base of this URL in the config.js. The base of the REST API URL and the GraphQL API URL are the same, just trim off the "/api/rest" part.
  6. Use the CQL Console to create the tables defined in the schema.cql file
  7. In the root of this project, run npm test to exercise all the APIs.

Related Articles

spring
angular
rest

GitHub - jhipster/jhipster-sample-app-cassandra: This is a sample application created with JHipster, with the Cassandra option

jhipster

3/7/2024

Checkout Planet Cassandra

Claim Your Free Planet Cassandra Contributor T-shirt!

Make your contribution and score a FREE Planet Cassandra Contributor T-Shirt! 
We value our incredible Cassandra community, and we want to express our gratitude by sending an exclusive Planet Cassandra Contributor T-Shirt you can wear with pride.

Join Our Newsletter!

Sign up below to receive email updates and see what's going on with our company

Explore Related Topics

AllKafkaSparkScyllaSStableKubernetesApiGithubGraphQl

Explore Further

rest