Search
Close this search box.

New Features to Cassandra.API

A bit has changed since we first announced our new application for DataStax Astra, Cassandra as a service hosted on the cloud. In our first blog post, we walked you through how our program allows you to import data into Astra, how to set up a Node or Python API that will allow you to communicate with your Astra database and how to run unit tests test to ensure that you are connected properly. Since then, we’ve added a read and write functionality to our APIs as well as user interface admin that will allow you to visualize your Astra database. Let’s take a look at what is new with Cassandra.API.

NOTE: The instructions in this blog post are under the assumption that you have already ran the data migrator and currently have either the Node or Python API running. Also we’ll be running this code on Gitpod.

Postman R/W

Node API

First, using Postman, we will make a GET request to http://localhost:8000/api/leaves/ to get an array of all items in the database.

ArpImg1

Upon hitting send, then results will be returned in a JSON format. The response status can be seen in the right hand corner with time taken and the size of the response:

ArpImg2

To make a POST request to http://localhost:8000/api/leaves/, we will need a request body with a key value of {“url” : “”}.

ArpImg31

We will get a JSON response of the new item.

ArpImg32

To make a request to https://localhost:8000/api/leaves/:id, we can use the first returned response from the last GET request and insert that item’s id as a parameter:

ArpImg3

After hitting send, the response should return only one item, the one associated with that specific id. Notice the size of the response is much smaller than when running the prior:

ArpImg4

To make a DELETE request via https://localhost:8000/api/leaves/:id, the same steps are followed as before. Take a specific item’s id, and insert that into the URL, but change the GET to a DELETE:

ArpImg5

After sending the request, you should see a response code of 200 and a JSON with a message:

ArpImg6

To handle errors when trying to delete an item that doesn’t exist, re-run the DELETE request that was just run and you will see another JSON message, but with a different response status code:

ArpImg7

To make a PATCH request via https://localhost:8000/api/leaves/:id, we will need a request body of any of the following key value pairs: title, tags, is_archived, is_starred, content, language, preview_picture, is_public, and url. We will send a request body of title and tags.

ArpImg33

The JSON response will be shown below.

ArpImg34

To get all tags associated with an item, we will make a GET request to http://localhost:8000/api/leaves/:id/tags. These will be the tags that we updated from the PATCH request before.

ArpImg35

To add tags to an associated item, we will need to make a POST request to http://localhost:8000/api/leaves/:id/tags and will require a request body as shown below.

ArpImg36

After hitting send, we will see the existing tags with the new tags we sent with the POST request.

ArpImg37

To delete tags associated with an item, we will make a DELETE request to http://localhost:8000/api/leaves/:id/tags and the response will be shown below.

ArpImg38

Going back to the code terminal, you can see a list of requests that were made and the response codes associated with those requests:

ArpImg39

Python API

Grab your gitpod-given url add /api/leaves to the end and paste into the url space in postman. Hit the send button. Your response should be a list of all of the entries in your astra table. Grab an id value from one of the entries to use in later steps.

ObiImg

Test getting single entries by adding the id you got to the end of the URL and hit send. This should return that single entry and no others. If you try with an id that is not in the table, you will get a 404 page.

ObiImg
ObiImg

The delete postman request is similar to the one that gets a single entry but the parameter to the left of the url is changed to delete

ObiImg

When run, you will get a 404 page returned. The get for that id will also start to return 404 pages.

ObiImg

In order to post new entries, create a POST request with the header, Content-Type application/json and the body of a json entry with the key URL and a string containing a URL.

ObiImg

This request will return the entry created from the url in full. It may be a good idea to grab the id generated during the process to use in later steps. In this case the id is 897ad25b3dc170fae9f72cd07a59517a.

ObiImg

To edit existing entries send a PATCH request to [gitpod generated url]/api/leaves/[chosen id] with the header, Content-Type application/json and the body of a json entry with the keys of fields you wish to change with the desired data as the value.

ObiImg

This returns the edited entry in full. This changes the “all” field appropriately.

ObiImg
ObiImg

In order to retrieve the tags send a get request to [gitpod generated url]/api/leaves/[chosen id]/tags. This will return a list of tags.

ObiImg
ObiImg

To add more tags to an entry, send a POST request to [gitpod generated url]/api/leaves/[chosen id]/tags with the header, Content-Type application/json and the body of a json entry with the key tags and the value of a list of desired tags. This also updates the slugs field.

ObiImg
ObiImg
ObiImg

To delete the tags of an entry, send a DELETE request to [gitpod generated url]/api/leaves/[chosen id]/tags. This deletes all of the tags attached to this entry. It returns the entire updated entry but the tags and slugs will both be null.

ObiImg
ObiImg

CRUD Interface

This is the last new addition to our Cassandra.API project. We used prior art to set up a UI to visualize our database in Astra.

In the base directory, add the following .env This will skip eslint pre-flight checks

SKIP_PREFLIGHT_CHECK=true

Next, run npm install to install the dependencies.

Afterwards, navigate to http://localhost:3000 to view your Admin UI.

Astra

As seen above, our Astra database is now visible in table format and you are able to update and delete records in this view as well. Feel free to re-run the Unit Tests to verify your data via REST. In the future, we hope to be able to add the option to “add” new records to your database as well so be on the lookout for that.

Conclusion

That just about concludes all the changes that have been made to Cassandra.API over the last two iterations. As time goes on, we plan on maintaining and improving our application to provide a better experience for those who use our tool. In case you’re wondering, we also have a few videos that cover each section of Cassandra.API and those can be found on your YouTube.