This is a Blog REST API built using Django and the Django REST framework. It is hosted on an AWS EC2 instance and can be accessed here. I do not keep it available at all times, however, due to the limitations of the AWS free-tier plan.
- Swagger Docs API documentation
- JSON Web Token (JWT) for authentication
- Nginx as a reverse proxy
- Redis for caching
- Throttling to prevent abuse
- Free SSL certificates using Certbot (for HTTPS)
- Comprehensive unit tests
A sample of the static API documentation is hosted on GitHub Pages. When the production API is live, the documentation can be found here and you can interact with it like any other API.
- Django and Django REST framework (DRF)
- Docker
- AWS (EC2, RDS, Route53)
- Nginx
- Redis
- JSON Web Token (JWT)
- PostgreSQL
- Certbot for HTTPS
- Python 3.11.8 or higher
- Docker 24.0.7 or later
- A
.env.dev
or.env.prod
file located in the root directory
# Django
SECRET_KEY="your-default-secret-key"
DJANGO_ALLOWED_HOSTS="127.0.0.1 localhost"
DEBUG=1 # For development ONLY
# Django DB settings
DB_ENGINE="django.db.backends.postgresql"
DB_NAME="yourdb"
DB_USER="youruser"
DB_PASSWORD="yourpassword"
DB_HOST="db"
DB_PORT="5432"
# PostgreSQL on Docker
POSTGRES_USER="youruser"
POSTGRES_PASSWORD="yourpassword"
POSTGRES_DB="yourdb"
This project is designed to run with Docker. However, you can also run the Django application independently (using the Setup Django instructions), which is often convenient during development. This means, however, that Nginx will no longer serve as a revere proxy, and Redis will need to be started manually. Additionally, in a production environment, you will no longer have Certbot for HTTPS. It is also important to know that the Django (development) server is not designed for use in a production environment, as stated here.
-
Clone the repository:
git clone https://github.com/okeneo/BlogAPI.git
-
Build the Docker images:
docker-compose -f docker-compose.dev.yml build
-
Start the containers:
docker-compose -f docker-compose.dev.yml up
-
In a separate terminal, run the following command to collect static files for Django to serve:
docker exec -it blogapi-api-1 python manage.py collectstatic --no-input
-
Clone the repository:
git clone https://github.com/okeneo/BlogAPI.git
-
Navigate to the project directory:
cd BlogAPI
-
Create, then activate a virtual environment (Recommended):
python -m venv .venv source .venv/bin/activate
-
Install dependencies:
cd api python -m pip install -r requirements.txt
-
Apply migrations
python manage.py migrate
-
Start the server:
python manage.py runserver
-
Navigate to the
api
directory:cd BlogAPI cd api
-
Run unit test Django command:
python manage.py test