
- Created FastAPI application with Todo CRUD operations - Implemented GET /api/v1/todos/ for listing todos with pagination - Implemented POST /api/v1/todos/ for creating new todos - Implemented GET /api/v1/todos/{id} for retrieving specific todos - Implemented PUT /api/v1/todos/{id} for updating todos - Implemented DELETE /api/v1/todos/{id} for deleting todos - Added proper error handling with 404 responses - Configured SQLAlchemy with SQLite database - Set up Alembic for database migrations - Added Pydantic schemas for request/response validation - Enabled CORS for all origins - Added health check endpoint at /health - Updated README with complete API documentation
90 lines
2.7 KiB
Markdown
90 lines
2.7 KiB
Markdown
# Todo API
|
|
|
|
A simple Todo API built with FastAPI, SQLAlchemy, and SQLite.
|
|
|
|
## Features
|
|
|
|
- Full CRUD operations for todos
|
|
- RESTful API design
|
|
- Automatic API documentation with Swagger/OpenAPI
|
|
- SQLite database with SQLAlchemy ORM
|
|
- Database migrations with Alembic
|
|
- CORS enabled for all origins
|
|
- Health check endpoint
|
|
|
|
## API Endpoints
|
|
|
|
### Base Endpoints
|
|
|
|
- `GET /` - Root endpoint with API information
|
|
- `GET /health` - Health check endpoint
|
|
- `GET /docs` - Swagger UI documentation
|
|
- `GET /redoc` - ReDoc documentation
|
|
|
|
### Todo Endpoints
|
|
|
|
All todo endpoints are prefixed with `/api/v1/todos`
|
|
|
|
- `GET /api/v1/todos/` - List all todos (with pagination)
|
|
- Query parameters: `skip` (default: 0), `limit` (default: 100)
|
|
- `POST /api/v1/todos/` - Create a new todo
|
|
- `GET /api/v1/todos/{todo_id}` - Get a specific todo by ID
|
|
- `PUT /api/v1/todos/{todo_id}` - Update a todo by ID
|
|
- `DELETE /api/v1/todos/{todo_id}` - Delete a todo by ID
|
|
|
|
## Data Model
|
|
|
|
Each todo has the following fields:
|
|
|
|
- `id` (integer) - Unique identifier
|
|
- `title` (string, required) - Todo title (1-200 characters)
|
|
- `description` (string, optional) - Todo description (max 1000 characters)
|
|
- `completed` (boolean) - Completion status (default: false)
|
|
- `created_at` (datetime) - Creation timestamp
|
|
- `updated_at` (datetime) - Last update timestamp
|
|
|
|
## Quick Start
|
|
|
|
1. Install dependencies:
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
2. Start the application:
|
|
```bash
|
|
uvicorn main:app --reload
|
|
```
|
|
|
|
3. The API will be available at `http://localhost:8000`
|
|
- API documentation: `http://localhost:8000/docs`
|
|
- Alternative docs: `http://localhost:8000/redoc`
|
|
|
|
## Database
|
|
|
|
The application uses SQLite with the database file stored at `/app/storage/db/db.sqlite`. Database tables are automatically created when the application starts.
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
/
|
|
├── main.py # FastAPI application entry point
|
|
├── requirements.txt # Python dependencies
|
|
├── alembic.ini # Alembic configuration
|
|
├── alembic/ # Database migrations
|
|
├── app/
|
|
│ ├── __init__.py
|
|
│ ├── api/ # API routes
|
|
│ │ ├── __init__.py
|
|
│ │ └── todos.py # Todo CRUD endpoints
|
|
│ ├── db/ # Database configuration
|
|
│ │ ├── __init__.py
|
|
│ │ ├── base.py # SQLAlchemy Base
|
|
│ │ └── session.py # Database session management
|
|
│ ├── models/ # SQLAlchemy models
|
|
│ │ ├── __init__.py
|
|
│ │ └── todo.py # Todo model
|
|
│ └── schemas/ # Pydantic schemas
|
|
│ ├── __init__.py
|
|
│ └── todo.py # Todo request/response schemas
|
|
```
|