A REST API built with FastAPI that allows users to register, log in, and manage their own tasks. Each user can only view and manage tasks they created. Tasks are stored in a local SQLite database using SQLModel.
- User registration and login
- JWT-based authentication
- Per-user task isolation
- Add, view, update, and delete tasks
- SQLite storage via SQLModel
- Input validation using Pydantic
- HTTP error handling
Clone the repository:
git clone https://github.com/cosmos-creator/Basic-FastAPI-ToDo-List-API.git
cd Basic-FastAPI-ToDo-List-APIInstall dependencies:
pip install fastapi uvicorn sqlmodel passlib[bcrypt] python-jose[cryptography] python-dotenv python-multipartSet up your .env file:
SECRET_KEY=your_secret_key_here
uvicorn main:app --reloadAvailable at http://127.0.0.1:8000 — interactive docs at http://127.0.0.1:8000/docs
POST /register — Create a new account
{
"username": "cosmos-creator",
"password": "yourpassword"
}POST /login — Returns a JWT token (use the Authorize button in /docs)
GET / — Returns all tasks belonging to the logged-in user
POST /add — Add a new task
{
"name": "Finish project",
"description": "Complete FastAPI To-Do API"
}PUT /update/{id} — Update an existing task by ID
{
"name": "Updated task name",
"description": "Updated description"
}DELETE /delete?id=1 — Delete a task by ID (only if it belongs to you)
- Register via
POST /register - Log in via the Authorize button in
/docs - All task routes are protected — requests without a valid token are rejected with 401
| Status | Reason |
|---|---|
| 401 | Invalid credentials or missing/expired token |
| 403 | Attempting to modify another user's task |
| 404 | Task not found |
| 409 | Username already taken |
- Python
- FastAPI
- SQLModel
- SQLite
- JWT (python-jose)
- passlib (bcrypt)
Built as a learning project to practice:
- REST API development
- JWT authentication
- Database integration with SQLModel
- Dependency injection
- Per-user data isolation