Designing Restful Api for pulling data from Cassandra Databases using Django Framework
- Django: The web framework for perfectionists with deadlines (Django builds better web apps with less code).
- DRF: A powerful and flexible toolkit for building Web APIs
- Django_Cassandra_Engine: first Cassandra backend for Django Framework.
-
If you wish to run your own build, first ensure you have python globally installed in your computer. If not, you can get python here.
-
After doing this, confirm that you have installed virtualenv globally as well. If not, run this:
$ pip install virtualenv
-
Now, create a virtual environment within the project directory by typing
$ virtualenv newenv
-
To install packages into the isolated environment, you must activate the virtual enviroment by typing
$ source newenv/bin/activate
-
Set-up Cassandra into your system
- Add a Personal Package Archives (PPA) using this command to install Oracle JRE package
sudo add-apt-repository ppa:webupd8team/java
- Update the package database:
sudo apt-get update
- Then install the Oracle JRE
sudo apt-get install oracle-java8-set-default
- After installing it, verify that it's now the default JRE:
java -version
- We’ll install Cassandra using packages from the official Apache Software Foundation repository provided by Datastax, so start by adding the repo so that the packages are available to your system.
- DataStax source for stable version of Cassandra
echo "deb http://debian.datastax.com/community stable main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
- To avoid package signature warnings during package updates, we need to add three public keys from the Apache Software Foundation associated with the package repositories.
gpg --keyserver pgp.mit.edu --recv-keys F758CE318D77295D
gpg --export --armor F758CE318D77295D | sudo apt-key add -
gpg --keyserver pgp.mit.edu --recv-keys 2B5C1B00
gpg --export --armor 2B5C1B00 | sudo apt-key add -
gpg --keyserver pgp.mit.edu --recv-keys 0353B12C
gpg --export --armor 0353B12C | sudo apt-key add -
- Update the package database once again:
sudo apt-get update
- Finally, install Cassandra
sudo apt-get install cassandra
- If you were able to successfully start Cassandra, check the status of the cluster. If the status is UN, it means it's Up and Normal.
sudo nodetool status
- Then connect to it using its interactive command line interface cqlsh.
cqlsh
- Type exit to quit
exit
-
Then, Git clone this repo to your PC
$ git clone https://github.com/hasan356/Todo_App.git
-
Cd into your the cloned repo as such:
$ cd Todo_App/myproject/
-
Install the dependencies needed to run the app:
$ pip install -r requirements.txt
-
Make those migrations work Sync it with Cassandra DB
$ python manage.py sync_cassandra
# http://localhost:8000/todo api for creating the todo task
# http://localhost:8000/todo/<key>/detail to see the detail of specific task
# http://localhost:8000/todo/<key>/update for update the specific task
# http://localhost:8000/todo/<key>/delete for delete the specific task