Task management REST API with JWT authentication and role-based access control.
Built with FastAPI and MongoDB.
- User registration and login (JWT)
- Role-based access control (admin/user)
- Task CRUD operations
- Profile management
- PDF export
# install dependencies
pip install -r requirements.txt
# run server
uvicorn main:app --reloadMake sure MongoDB is running first.
POST /auth/register- create accountPOST /auth/login- get tokenGET /auth/profile- view profile (token required)PUT /auth/profile- update profile (token required)
POST /tasks- create taskGET /tasks- list all tasksGET /tasks/export/pdf- download as PDFGET /tasks/{id}- get single taskPUT /tasks/{id}- update taskDELETE /tasks/{id}- delete task
GET /admin/users- list all usersPUT /admin/users/{username}/role- change user role
Register:
curl -X POST http://127.0.0.1:8000/auth/register \
-H "Content-Type: application/json" \
-d '{"username": "ali", "email": "ali@test.com", "password": "123456"}'Login:
curl -X POST http://127.0.0.1:8000/auth/login \
-H "Content-Type: application/json" \
-d '{"username": "ali", "password": "123456"}'Create task (with token):
curl -X POST http://127.0.0.1:8000/tasks \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"title": "my task", "priority": 2}'Export PDF:
curl -H "Authorization: Bearer YOUR_TOKEN" \
http://127.0.0.1:8000/tasks/export/pdf \
-o tasks.pdfpytest tests/ -v- FastAPI
- MongoDB
- PyMongo
- Pydantic
- python-jose (JWT)
- reportlab (PDF)
- pytest
taskflow/
├── main.py
├── app/
│ ├── config/ # settings, database, security, logging
│ ├── models/ # pydantic schemas
│ ├── services/ # business logic (CRUD, PDF)
│ └── routes/ # API endpoints
└── tests/
- User-task relationship
- Pagination
- Refresh token