In this coding assignment I have implemented a CRUD (Create, Read, Update, Delete) API with a database deployed in Heroku Postgresql. To implement this assignment I have used Django framework and have deployed the API on Heroku cloud hosting provider. I have created a sample dataset for books with name, isbn, authors, country, number_of_pages, publisher release_date as its attributes.
You can access the API using following API call:
https://balajibookmanagementapp.herokuapp.com/api/book/
I have deployed the working API on Heroku, you can see use following website to look at its woking:
https://balajibookmanagementapp.herokuapp.com/api/book/
The backend dataset which I have used is postgresql deployed on Heroku cloud platform. You can add, read, update or delete any record from the dataset. Below I have given examples for the CRUD operations which you can perform on the dataset.
For creating a new Book record, you can either use above mentioned website and add the record as shown in the adjacent screenshot using UI provided or you can as well use an API testing tool like Postman.
Or you can use Postman as shown below to create a new book record:
For reading the book dataset which I have uploaded on Heroku postgresql cloud services, we can hit the API using above given link and can get the response in JSon as shown below:
Or you can use Postman as shown below to read the books dataset:
You can also fetch a particular book info with by providing the book id as below:
Same thing we can do using Postman or any other API testing tool as well:
As shown below, we can update a record by calling the API by "https://balajibookmanagementapp.herokuapp.com/api/book/4/" and using PUT option given at the bottom as follows:
To update a record in our dataset we can call our API using PUT method as shown below, here I have changed the ISBN number of book named "balaji book".
We can delete a record from the dataset by by calling the API as follows, for example here I've tried deleting the book record with id 1 by calling
https://balajibookmanagementapp.herokuapp.com/api/book/1/
we get an option to delete it as shown in the screenshot below:
Or we can also use Postman to delete a record from our dataset, we need to call our API using DELETE method which I have shown below:
Thus, after deleting 8th record we have our dataset as follows:
The first thing to do is to clone the repository:
$ git clone https://github.com/balaji2245/django_project.git
Create a virtual environment to install dependencies in and activate it:
$ virtualenv2 --no-site-packages env
$ source env/bin/activate
Then install the dependencies:
(env)$ pip install -r requirements.txt
Note the (env)
in front of the prompt. This indicates that this terminal
session operates in a virtual environment set up by virtualenv2
.
Once pip
has finished downloading the dependencies:
(env)$ cd project
(env)$ python manage.py runserver
And navigate to http://127.0.0.1:8000/balaji2245/
.