Automated Action 9c5b74200b Setup basic FastAPI project with Todo API
- Created requirements.txt with necessary dependencies
- Set up FastAPI application structure with main.py
- Added health endpoint
- Configured SQLAlchemy with SQLite database
- Initialized Alembic for database migrations
- Created Todo model and API endpoints
- Updated README with setup and usage instructions
- Linted code with Ruff
2025-05-29 02:07:19 +00:00

143 lines
2.7 KiB
Markdown

# Todo List API
A simple Todo List API built with FastAPI and SQLite. This API allows you to create, read, update, and delete todo items.
## Features
- RESTful API with CRUD operations for todo items
- SQLite database with SQLAlchemy ORM
- Database migrations with Alembic
- Auto-generated API documentation with Swagger UI and ReDoc
- Health check endpoint
- Code linting with Ruff
## Requirements
- Python 3.8+
- FastAPI
- SQLAlchemy
- Alembic
- Uvicorn
- SQLite
## Setup
1. Clone the repository
2. Install the dependencies:
```bash
pip install -r requirements.txt
```
3. Run the database migrations:
```bash
alembic upgrade head
```
4. Start the API server:
```bash
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
```
## API Endpoints
- `GET /`: Root endpoint with welcome message
- `GET /health`: Health check endpoint
- `GET /docs`: Auto-generated API documentation (Swagger UI)
- `GET /redoc`: Alternative API documentation (ReDoc)
- `GET /openapi.json`: OpenAPI schema
### Todo Endpoints
- `GET /todos`: Get all todo items
- `GET /todos/{todo_id}`: Get a specific todo item
- `POST /todos`: Create a new todo item
- `PUT /todos/{todo_id}`: Update a todo item
- `DELETE /todos/{todo_id}`: Delete a todo item
## API Usage Examples
### Create a Todo Item
```bash
curl -X 'POST' \
'http://localhost:8000/todos' \
-H 'Content-Type: application/json' \
-d '{
"title": "Buy groceries",
"description": "Milk, eggs, bread",
"completed": false
}'
```
### Get All Todo Items
```bash
curl -X 'GET' 'http://localhost:8000/todos'
```
### Get a Specific Todo Item
```bash
curl -X 'GET' 'http://localhost:8000/todos/1'
```
### Update a Todo Item
```bash
curl -X 'PUT' \
'http://localhost:8000/todos/1' \
-H 'Content-Type: application/json' \
-d '{
"title": "Buy groceries",
"description": "Milk, eggs, bread, cheese",
"completed": true
}'
```
### Delete a Todo Item
```bash
curl -X 'DELETE' 'http://localhost:8000/todos/1'
```
## Database Schema
The database schema consists of a single `todos` table with the following columns:
- `id`: Integer, Primary Key
- `title`: String, Not Null
- `description`: String, Nullable
- `completed`: Boolean, Default: False
- `created_at`: DateTime, Default: Current Timestamp
- `updated_at`: DateTime, Nullable
## Development
For local development, you can use the following commands:
- Start the application with auto-reload:
```bash
uvicorn main:app --reload
```
- Run Ruff for linting:
```bash
ruff check .
```
- Run Ruff for auto-fix:
```bash
ruff check --fix .
```
- Create a new migration:
```bash
alembic revision -m "Your migration message"
```
- Run migrations:
```bash
alembic upgrade head
```
## License
This project is licensed under the MIT License.