2.4 KiB
2.4 KiB
Todo API Application
This is a FastAPI Todo API application with SQLite database that provides a complete CRUD functionality for managing todo items. Removing all edits made so far
Features
- Create, read, update, and delete todo items
- RESTful API with proper HTTP status codes
- SQLite database for storage
- API documentation with Swagger and ReDoc
- Alembic for database migrations
Project Structure
todoapiapplication/
├── alembic/ # Database migrations
│ └── versions/ # Migration scripts
├── api/ # API implementation
│ └── routes/ # API route handlers
├── db/ # Database configuration
├── models/ # SQLAlchemy ORM models
├── schemas/ # Pydantic schemas/models
├── services/ # Business logic layer
├── tests/ # Test files
├── alembic.ini # Alembic configuration
├── main.py # Application entry point
└── requirements.txt # Project dependencies
API Endpoints
Method | Endpoint | Description | Request Body | Response |
---|---|---|---|---|
GET | /api/todos/ | Get all todos | - | List of todos |
POST | /api/todos/ | Create a new todo | Todo object | Created todo |
GET | /api/todos/id | Get a todo by ID | - | Todo object |
PUT | /api/todos/id | Update a todo by ID | Todo object | Updated todo |
DELETE | /api/todos/id | Delete a todo by ID | - | No content (204) |
Setup and Installation
- Clone the repository
- Install the dependencies:
pip install -r requirements.txt
- Run the application:
uvicorn main:app --reload
- The API will be available at:
http://localhost:8000
- API documentation:
http://localhost:8000/docs
orhttp://localhost:8000/redoc
Database Migrations
Migrations are handled by Alembic:
# Apply migrations
alembic upgrade head
# Create a new migration
alembic revision -m "description"
Todo Model
id
: Integer (Primary Key)title
: String (Required)description
: String (Optional)completed
: Boolean (Default: False)created_at
: DateTimeupdated_at
: DateTime