Difficulty: Intermediate
Estimated Time: 15 minutes

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 insertGame endpoint 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™.


Code Complete

Check out the full BattleStax Workshop!

For more information and details on using the Document API on Astra read the documentation, or try out this scenario to learn the basics.

Please give this scenario a rating (click on the stars near the top).

Have questions or more feedback? Send us a message.

Create a Serverless REST Endpoint

Step 1 of 7

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:

cd battlestax

Copy and paste the contents of the .env.example file into an .env file

cp ~/battlestax/.env.example ~/battlestax/.env

Let's open our new copy in the text editor


The .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 games.

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.

env vars


The .env file in the text editor should look something like this:

env vars

With those set, we're ready to get started!