This is a user-friendly API using Django Rest Framework (DRF) for a bookstore management system. The main idea is to offer a bunch of useful functions for handling book information effortlessly. Users can do everything from adding, viewing, and updating, to removing book details. Plus, it also offers a neat feature where users can neatly organize their booklists by creating categories.
The API is well documented for each endpoint here
| Http Verb | ApiEndpoint | Usage |
|---|---|---|
| POST | /api/books/ | Add a new book |
| GET | /api/books/ | Get all available books |
| GET | /api/books/:id/ | Get a book and see details |
| PUT | /api/books/:id/ | Update a book |
| DELETE | /api/books/:id/ | Delete a book |
| GET | /api/categories/ | Get all available categories |
| GET | /api/categoriess/:id/ | Get a category |
This application is containerized with Docker and has two services setup and configured to run on the same network for extra security.
Follow the following setup instructions to run this on your local environment:
- Docker/Docker Desktop
- Python 3.12.0
- Django 4.2.6
- Django Rest Framework 3.14.0
- Postgresql 13.12
- Pip
-
Clone the project on your machine:
git clone https://github.com/ClaytonSiby/helm_bookstore_api.git -
Change directory to this project's root:
cd helm_bookstore_api -
To run the application on your local:
- Run
pip install virtualenvto install virtualenv an essential tool for creating a virtual environment for the project. - Run
virtualenv .venvto create the virtual environment (the name can be anything) - Run
source ./.venv/bin/activateto activate the environment (this ensures that all dependencies installed are only changed on your current environment, e.t.c) - Run
pip install -r requirements.txtto install all dependencies essential for this project - make sure the helm_bookstore/settings.py db configuration looks like this (the
localhostis your db host) e.g:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'bookstore_db',
'USER': 'helm_admin',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '5432',
}
}
- Run
chmod +x ./build.sh && ./build.shtomakemigrations,migrate, and start a gunicorn server onhttp://0.0.0.0:8000 - Run
python manage.py testto run all available tests for the project
- To run in a container:
- Setup docker stack: > this will setup two services (
api,db, andnginx) on the same network (i.e helm_network): docker-compose build --no-cache> install dependencies as descriped in the Dockerfile- make sure the helm_bookstore/settings.py db configuration looks like this (the
dbis your host):
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'bookstore_db',
'USER': 'helm_admin',
'PASSWORD': 'password',
'HOST': 'db',
'PORT': '5432',
}
}
docker-compose up> which does the following:- creates a
helm_bookstore_projectdocker stack and establishes thehelm_network - creates a
helm_bookstore_apicontainer (the djangon/rest framework project) - creates a
helm_bookstore_dbcontainer (postgresql database container) - creates a
nginxcontainer - runs
./build.shtomakemigrations,migrate, and bind a gunicorn server onhttp://0.0.0.0:8000
- Access available resources on the API via the above endpoints (provided in the table)
- NB - if you get a 404 No Content View, make sure you are using the right endpoint and try again!