
- Set up FastAPI project structure - Configure SQLAlchemy with SQLite - Create Todo model and schemas - Implement CRUD operations - Add API endpoints for Todo management - Configure Alembic for database migrations - Add health check endpoint - Add comprehensive documentation
119 lines
3.1 KiB
Markdown
119 lines
3.1 KiB
Markdown
# SimpleTodoAPI
|
|
|
|
A simple FastAPI-based RESTful API for managing todo items with SQLite database.
|
|
|
|
## Features
|
|
|
|
- Create, read, update, and delete todo items
|
|
- SQLite database with SQLAlchemy ORM
|
|
- Database migrations with Alembic
|
|
- API documentation with Swagger UI and ReDoc
|
|
- Health check endpoint
|
|
- Input validation with Pydantic
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
.
|
|
├── alembic.ini # Alembic configuration
|
|
├── app # Application package
|
|
│ ├── api # API endpoints
|
|
│ │ └── routes # API routes
|
|
│ │ ├── health.py # Health check endpoint
|
|
│ │ └── todo.py # Todo endpoints
|
|
│ ├── core # Core module
|
|
│ │ └── config.py # Application configuration
|
|
│ ├── crud # CRUD operations
|
|
│ │ └── todo.py # Todo CRUD operations
|
|
│ ├── db # Database module
|
|
│ │ ├── base.py # Base DB class and model imports
|
|
│ │ └── session.py # Database session management
|
|
│ ├── models # SQLAlchemy models
|
|
│ │ └── todo.py # Todo model
|
|
│ └── schemas # Pydantic schemas
|
|
│ └── todo.py # Todo schemas
|
|
├── main.py # Application entry point
|
|
├── migrations # Alembic migrations
|
|
│ ├── env.py # Alembic environment
|
|
│ ├── script.py.mako # Migration script template
|
|
│ └── versions # Migration versions
|
|
│ └── 20231031_010000_create_todos_table.py # Initial migration
|
|
└── requirements.txt # Project dependencies
|
|
```
|
|
|
|
## API Endpoints
|
|
|
|
- **GET /health** - Health check endpoint
|
|
- **GET /api/v1/todos/** - List all todos
|
|
- **POST /api/v1/todos/** - Create a new todo
|
|
- **GET /api/v1/todos/{todo_id}** - Get a specific todo
|
|
- **PUT /api/v1/todos/{todo_id}** - Update a todo
|
|
- **DELETE /api/v1/todos/{todo_id}** - Delete a todo
|
|
|
|
## API Documentation
|
|
|
|
When the server is running, you can access:
|
|
- Swagger UI: http://localhost:8000/docs
|
|
- ReDoc: http://localhost:8000/redoc
|
|
|
|
## Requirements
|
|
|
|
- Python 3.7+
|
|
- FastAPI
|
|
- Uvicorn
|
|
- SQLAlchemy
|
|
- Alembic
|
|
- Pydantic
|
|
- Ruff (for linting)
|
|
|
|
## Installation
|
|
|
|
```bash
|
|
# Clone the repository
|
|
git clone <repository-url>
|
|
|
|
# Change to the project directory
|
|
cd simpletodoapi
|
|
|
|
# Install dependencies
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
## Database Setup
|
|
|
|
```bash
|
|
# Apply database migrations
|
|
alembic upgrade head
|
|
```
|
|
|
|
## Running the Application
|
|
|
|
```bash
|
|
# Start the server
|
|
uvicorn main:app --reload
|
|
```
|
|
|
|
The API will be available at http://localhost:8000.
|
|
|
|
## Development
|
|
|
|
### Creating new migrations
|
|
|
|
```bash
|
|
# Generate a new migration
|
|
alembic revision -m "description of changes"
|
|
```
|
|
|
|
### Linting
|
|
|
|
```bash
|
|
# Run ruff linter
|
|
ruff check .
|
|
|
|
# Run ruff formatter
|
|
ruff format .
|
|
```
|
|
|
|
## License
|
|
|
|
This project is licensed under the MIT License. |