
- Add comprehensive todo endpoints in app/api/endpoints/todos.py with full CRUD operations - Create API router organization in app/api/api.py - Integrate API routes with main FastAPI app using /api/v1 prefix - Include proper HTTP status codes, error handling, and REST conventions - Add proper package initialization files for all modules - Clean up temporary validation and migration files - Update README with current project structure API endpoints available: - GET /api/v1/todos - list all todos - POST /api/v1/todos - create new todo - GET /api/v1/todos/{id} - get specific todo - PUT /api/v1/todos/{id} - update todo - DELETE /api/v1/todos/{id} - delete todo
106 lines
2.8 KiB
Markdown
106 lines
2.8 KiB
Markdown
# Todo App API
|
|
|
|
A simple Todo application API built with FastAPI and SQLite.
|
|
|
|
## Features
|
|
|
|
- FastAPI web framework
|
|
- SQLite database with SQLAlchemy ORM
|
|
- Alembic database migrations
|
|
- CORS enabled for all origins
|
|
- Health check endpoint
|
|
- Interactive API documentation
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
todoapp-ns86xt/
|
|
├── main.py # FastAPI application entry point
|
|
├── requirements.txt # Python dependencies
|
|
├── alembic.ini # Alembic configuration
|
|
├── migrations/ # Database migration files
|
|
│ ├── env.py
|
|
│ ├── script.py.mako
|
|
│ └── versions/
|
|
├── app/ # Application modules
|
|
│ ├── db/ # Database configuration
|
|
│ │ ├── base.py # SQLAlchemy Base
|
|
│ │ └── session.py # Database session management
|
|
│ ├── models/ # SQLAlchemy models
|
|
│ └── api/ # API endpoints
|
|
└── storage/ # Application storage directory
|
|
└── db/ # SQLite database files
|
|
```
|
|
|
|
## Installation
|
|
|
|
1. Install dependencies:
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
## Running the Application
|
|
|
|
Start the development server:
|
|
```bash
|
|
uvicorn main:app --reload --host 0.0.0.0 --port 8000
|
|
```
|
|
|
|
The application will be available at:
|
|
- API: http://localhost:8000
|
|
- Interactive API docs (Swagger): http://localhost:8000/docs
|
|
- Alternative API docs (ReDoc): http://localhost:8000/redoc
|
|
- OpenAPI JSON: http://localhost:8000/openapi.json
|
|
|
|
## API Endpoints
|
|
|
|
- `GET /` - Root endpoint with application information
|
|
- `GET /health` - Health check endpoint
|
|
- `GET /docs` - Interactive API documentation (Swagger UI)
|
|
- `GET /redoc` - Alternative API documentation (ReDoc)
|
|
|
|
## Database
|
|
|
|
The application uses SQLite database stored at `/app/storage/db/db.sqlite`. Database migrations are managed with Alembic.
|
|
|
|
### Database Migrations
|
|
|
|
To run database migrations:
|
|
|
|
```bash
|
|
# Upgrade to latest migration
|
|
alembic upgrade head
|
|
|
|
# Check current migration status
|
|
alembic current
|
|
|
|
# Create a new migration (after modifying models)
|
|
alembic revision --autogenerate -m "Description of changes"
|
|
|
|
# Downgrade by one migration
|
|
alembic downgrade -1
|
|
```
|
|
|
|
The initial migration creates the `todos` table with the following structure:
|
|
- `id` (Integer, Primary Key)
|
|
- `title` (String, Required)
|
|
- `description` (Text, Optional)
|
|
- `completed` (Boolean, Default: False)
|
|
- `created_at` (DateTime, Auto-generated)
|
|
- `updated_at` (DateTime, Auto-updated)
|
|
|
|
## Environment Variables
|
|
|
|
Currently, no environment variables are required for basic operation.
|
|
|
|
## Development
|
|
|
|
The project uses Ruff for code linting and formatting. Make sure to run linting before committing changes.
|
|
|
|
## Health Check
|
|
|
|
The `/health` endpoint provides information about:
|
|
- Application status
|
|
- Database connectivity
|
|
- Service version
|