Interested in seeing a real application leveraging Stargate APIs on DataStax Astra? Welcome to BattleStax, an online party game you can enjoy with your friends. Battlestax is implemented as a JAMStack app that uses Stargate, Netlify functions, Astra, and GitHub to demonstrate how to build and deploy an application using modern, scalable architectures.
Before we begin
As a prerequisite, be sure to setup an Astra account and create a Cassandra as a Service database at astra.datastax.com.
Watch this video on How to Create a Database with Astra in 2 minutes if you need more help.
In this scenario we will:
- Create a mock serverless REST endpoint that exposes a document API
- Create an
insertGameendpoint and connect to Astra
- Run TDD tests
Let's learn how to create serverless endpoints using Netlify functions in a development environment.
This scenario is also available on our datastax.com/dev site, where you can find many more resources to help you succeed with Apache Cassandra™.
Check out the full BattleStax Workshop!
Please give this scenario a rating (click on the stars near the top).
Have questions or more feedback? Send us a message.
Setting up Environment Variables
First of all, we will need set up some environment variables to help simplify our REST API access. Ensure that you have created an Astra database and keyspace in order to do this step.
Enter into the battlestax directory:
Copy and paste the contents of the
.env.example file into an
cp ~/battlestax/.env.example ~/battlestax/.env
Let's open our new copy in the text editor
.env file allows us to customize our own environment variables. Our Netlify functions will need to use these to connect to Astra. We set our Astra credentials to env variables, which are outside of our program. Fill in the
.env file variables with the Astra variables. You can get your database username, keyspace, database id and region from the Summary page in Astra. Keep the collection name as
Note: Our keyspace is equivalent to a namespace in when using the Document API. You you need to use an empty keyspace or a keyspace with only documents for this scenario.
ASTRA_DB_USERNAME=<your_db_username> ASTRA_DB_PASSWORD=<your_db_password> ASTRA_DB_KEYSPACE=<your_keyspace> ASTRA_DB_ID=<your_db_id> ASTRA_DB_REGION=<your_region> GAMES_COLLECTION=games
.env file in the text editor should look something like this: