
- Set up project structure with FastAPI, SQLAlchemy, and Alembic - Create Todo model and database operations - Implement CRUD API endpoints for Todo items - Configure database migrations - Add comprehensive documentation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
80 lines
1.9 KiB
Markdown
80 lines
1.9 KiB
Markdown
# FastAPI Todo Backend Service
|
|
|
|
This is a simple Todo API backend service built with FastAPI, SQLAlchemy, and SQLite.
|
|
|
|
## Features
|
|
|
|
- CRUD operations for Todo items
|
|
- API documentation with Swagger UI and ReDoc
|
|
- Database migrations with Alembic
|
|
- SQLite database
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
.
|
|
├── alembic/ # Database migrations
|
|
├── app/
|
|
│ ├── api/ # API endpoints
|
|
│ │ └── v1/ # API version 1
|
|
│ ├── core/ # Core application configurations
|
|
│ ├── db/ # Database connection and CRUD operations
|
|
│ ├── models/ # SQLAlchemy models
|
|
│ └── schemas/ # Pydantic schemas for request/response
|
|
├── main.py # Application entry point
|
|
├── requirements.txt # Python dependencies
|
|
└── alembic.ini # Alembic configuration
|
|
```
|
|
|
|
## Getting Started
|
|
|
|
1. Clone the repository
|
|
2. Install dependencies:
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
3. Run database migrations:
|
|
```bash
|
|
alembic upgrade head
|
|
```
|
|
4. Start the application:
|
|
```bash
|
|
uvicorn main:app --reload
|
|
```
|
|
|
|
## API Documentation
|
|
|
|
Once the application is running, you can access:
|
|
- Swagger UI: http://localhost:8000/docs
|
|
- ReDoc: http://localhost:8000/redoc
|
|
|
|
## API Endpoints
|
|
|
|
- GET `/api/v1/todos/`: List all todo items
|
|
- POST `/api/v1/todos/`: Create a new todo item
|
|
- GET `/api/v1/todos/{todo_id}`: Get a specific todo item
|
|
- PUT `/api/v1/todos/{todo_id}`: Update a todo item
|
|
- DELETE `/api/v1/todos/{todo_id}`: Delete a todo item
|
|
|
|
## Example
|
|
|
|
### Create a new todo
|
|
|
|
```bash
|
|
curl -X 'POST' \
|
|
'http://localhost:8000/api/v1/todos/' \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{
|
|
"title": "Buy groceries",
|
|
"description": "Milk, bread, eggs",
|
|
"completed": false
|
|
}'
|
|
```
|
|
|
|
### List all todos
|
|
|
|
```bash
|
|
curl -X 'GET' \
|
|
'http://localhost:8000/api/v1/todos/' \
|
|
-H 'accept: application/json'
|
|
``` |