This project is a Django-based REST API that provides a secure and efficient key-value storage system. It supports both simple and nested pairs, uses JWT authentication for secure access, and offers comprehensive API documentation through Swagger and ReDoc.
- User Authentication: Secure JWT-based user authentication with RS256 encryption.
- Key-Value Storage: Flexible handling of key-value data, supporting various data types and nested structures.
- Cursor Pagination: Handles large datasets efficiently.
- PostgreSQL Database: Optimized querying with advanced indexing.
- OpenAPI Documentation: Interactive API documentation with Swagger UI and ReDoc.
- Testing and Coverage: Automated test coverage reports to ensure reliability and maintainability.
- Production-ready Configuration: Deployment ready with
Docker
anddocker-compose
.
- core: Main configuration and settings files.
- users: Custom user model and authentication-related functionality.
- pairs: Key-value storage app with support for nested pairs.
- Python 3.8+
- Docker and Docker Compose
- PostgreSQL
- RSA private and public keys for JWT (place in
keys/private.pem
andkeys/public.pem
) - Create a
.env
file at the root of the project. Example content in.env.sample
file.
$ git clone https://github.com/amirkhgraphic/qtask-rest-api.git
$ cd qtask-rest-api
Create a .env
file at the root of the project. Example content in .env.sample
file.
$ pip install -r requirements.txt
If you don't have existing RSA keys, you can generate them using the following commands:
$ openssl genpkey -algorithm RSA -out keys/private.pem -pkeyopt rsa_keygen_bits:2048
$ openssl rsa -pubout -in keys/private.pem -out keys/public.pem
Build and run the project with Docker Compose:
$ docker-compose up --build
The application should now be available at http://localhost:8000.
- Swagger UI: http://localhost:8000/api/swagger-ui/
- ReDoc: http://localhost:8000/api/redoc/
Run tests with coverage and generate reports:
$ chmod +x test_coverage.sh
$ ./test_coverage.sh
The coverage reports will be generated in coverage_reports
:
- HTML report:
coverage_reports/html/index.html
- XML report:
coverage_reports/coverage.xml
- Text report:
coverage_reports/coverage_report.txt
The app uses SQLite and a console email backend for local development and
PostgreSQL and an SMTP email backend for production. you can switch between
them by toggling the PROD
environment variable.
PROD=True/False
The CustomCursorPagination
class in core.pagination
allows for cursor-based pagination, improving API response efficiency.
JWT authentication uses RS256
encryption. You can adjust token lifetimes in SIMPLE_JWT
settings in core/settings/base.py
:
SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=15),
'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
# other items
}