10 minutes, Beginner, Start Building
This is an example React To-Do application using a DataStax Astra free tier database.
There is nothing preventing you from running the workshop on your own machine. If you do so, you will need
- git installed on your local system
- node 15 and npm 7 or later
You will have to adapt commands and paths based on your environment and install the dependencies by yourself. We won't provide support to keep on track with schedule. However, we will do our best to give you the info you need to be successful.
What other prerequisites are there?
- You will need a github account
- You will also need an Astra DB account, but we'll work through that in the exercises
- Use Chrome or Firefox for the best experience. Other browsers are great, but don't work well with the GitPod integration we use a bit later.
Do I need to pay for anything for this workshop?
- No. All tools and services we provide here are FREE.
Will I get a certificate if I attend this workshop?
Attending the session is not enough. You need to complete the homework detailed below and you will get a nice badge.
It doesn't matter if you join our workshop live or you prefer to do at your own pace, we have you covered. In this repository, you'll find everything you need for this workshop:
Don't forget to complete your upgrade and get your verified skill badge! Finish and submit your homework!
That's it, you are done! Expect an email next week!
ASTRADB
is the simplest way to run Cassandra with zero operations at all - just push the button and get your cluster. No credit card required, $25.00 USD credit every month, roughly 5M writes, 30M reads, 40GB storage monthly - sufficient to run small production workloads.
Github
, Google
accounts or register with an email
.Make sure to chose a password with minimum 8 characters, containing upper and lowercase letters, at least one number and special character
Use the following values when creating the database | Field | Value |
---|---|---|
database name | todos_workshop_db |
|
keypace | todos |
|
Cloud Provider | Use the one you like, click a cloud provider logo, pick an Area in the list and finally pick a region. |
You can technically use whatever you want and update the code to reflect the keyspace. This is really to get you on a happy path for the first run.
You will see your new database pending
in the Dashboard.
The status will change to Active
when the database is ready, this will only take 2-3 minutes. You will also receive an email when it is ready.
β Step 2a: Create a token for your app to use in the settings screen. Use "Database Administrator" permission.
β
Step 2b: Copy the token value (eg AstraCS:KDfdKeNREyWQvDpDrBqwBsUB:ec80667c....
) in your clipboard and save the CSV, this value would not be provided afterward.
ποΈ Expected output
β Step 3a: Open Swagger by
Connect
TABREST API
As shown on the picture below.
β Step 3b: Navigate to create a table section
β Step 3c: Create table restfromreadme_by_id
todos
Finally, copy the create table statement using the code below into the body field
{
"name": "restfromreadme_by_id",
"ifNotExists": true,
"columnDefinitions": [
{
"name": "id",
"typeDefinition": "uuid",
"static": false
},
{
"name": "text",
"typeDefinition": "text",
"static": false
},
{
"name": "key",
"typeDefinition": "text",
"static": false
},
{
"name": "completed",
"typeDefinition": "boolean"
}
],
"primaryKey": {
"partitionKey": [
"id"
]
}
}
And click execute to apply the command and create the table
You should see a 201 response telling you it correctly created the "restfromreadme_by_id" table.
Again, take a note of the Request URL that was used to create the table. This comes into play later when we take a look at the code in astraRestClient.js
used to create our TODO application table.
Now that we have a table to use, let's insert a row of data into the table, again using REST to do so.
β Step 4a: Navigate to Add row section
β Step 4b: FIll in values and add a row
todos
restfromreadme_by_id
. Note, this is the table we created in the earlier step{"id":"57dbd260-d905-11eb-b985-c522859819b9","completed":false,"text":"TODO FROM README","key":"none"}
Finally, now that we created a table and inserted a row of data let's GET the data back out.
β Step 5a: Navigate to Retrieve all rows section
β Step 5b: Execute the command to display the data
todos
restfromreadme_by_id
β Step 7a: Retrieve application token to securely connect to the database
Use the token you previously generated. If you no longer have the token and did not download a .csv, you can generate a new token using the instructions above
β Step 7b: Configure Environment Variables and Install Dependencies
.env
fileIn the repository directory run the following command to set up your Astra environment. Note that this does require Node 15 and NPM 7 to work. You can install a node version manager like nvm
or n
to use multiple versions on your system.
npm exec astra-setup todos_workshop_db todos
npm install -g netlify-cli
β Step 7c: Launch your app
netlify dev