This is a backend Todo application built with FastAPI. The application allows users to create, read, update, and delete todo items, and includes user authentication and authorization features.
- User registration, authentication, and authorization using JWT tokens
- CRUD (Create, Read, Update, Delete) operations for todo items
- SQLite database integration for data persistence
- FastAPI dependency injection
- Swagger UI for API documentation
- Python 3.7+
- Git
git clone https://github.com/YourUsername/TodoApp-FastAPI.git
cd TodoApp-FastAPIpython -m venv .venv
source .venv/bin/activate # On Windows use `.venv\Scripts\activate`pip install -r requirements.txtCreate a .env file in the root directory and add the following environment variables:
SECRET_KEY=your_secret_key_here
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
Replace your_secret_key_here with a secure key of your choice.
The project uses SQLite by default. To set up the database, run:
alembic upgrade headThis will apply the necessary database migrations.
To start the FastAPI server, run:
uvicorn main:app --reloadThe application will be accessible at http://127.0.0.1:8000.
FastAPI provides interactive API documentation at the following URLs:
- Swagger UI:
http://127.0.0.1:8000/docs - ReDoc:
http://127.0.0.1:8000/redoc
- POST
/token: Obtain a JWT token by providing valid user credentials.
- POST
/users/: Register a new user. - GET
/users/me/: Get the details of the currently authenticated user.
- GET
/todos/: Get all todo items. - GET
/todos/{todo_id}: Get a specific todo item by ID. - POST
/todos/: Create a new todo item. - PUT
/todos/{todo_id}: Update an existing todo item by ID. - DELETE
/todos/{todo_id}: Delete a specific todo item by ID.
pip install pytest pytest-asynciopytestThis will run all the test cases in the project.
The application uses the following environment variables:
SECRET_KEY: The secret key used for generating JWT tokens.ALGORITHM: The algorithm used for encoding JWT tokens (default: HS256).ACCESS_TOKEN_EXPIRE_MINUTES: Token expiry time (default: 30 minutes).