
- Set up project structure and dependencies - Implement Todo model with SQLAlchemy - Configure SQLite database connection - Create Alembic migration scripts - Implement RESTful API endpoints for CRUD operations - Add health check endpoint - Update README with documentation generated with BackendIM... (backend.im)
109 lines
2.2 KiB
Markdown
109 lines
2.2 KiB
Markdown
# Simple Todo Application
|
|
|
|
A simple Todo application API built with FastAPI and SQLite.
|
|
|
|
## Features
|
|
|
|
- Create, read, update, and delete todo items
|
|
- SQLite database with SQLAlchemy ORM
|
|
- Alembic migrations
|
|
- Health check endpoint
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
├── alembic/ # Database migrations
|
|
├── app/ # Application package
|
|
│ ├── api/ # API endpoints
|
|
│ ├── core/ # Core configuration
|
|
│ ├── crud/ # CRUD operations
|
|
│ ├── db/ # Database setup
|
|
│ ├── models/ # SQLAlchemy models
|
|
│ └── schemas/ # Pydantic schemas
|
|
├── alembic.ini # Alembic configuration
|
|
├── main.py # FastAPI application
|
|
└── requirements.txt # Python dependencies
|
|
```
|
|
|
|
## Installation
|
|
|
|
1. Clone the repository:
|
|
|
|
```bash
|
|
git clone https://github.com/yourusername/simpletodoapplication.git
|
|
cd simpletodoapplication
|
|
```
|
|
|
|
2. Install dependencies:
|
|
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
3. Run database migrations:
|
|
|
|
```bash
|
|
alembic upgrade head
|
|
```
|
|
|
|
## Usage
|
|
|
|
Start the application:
|
|
|
|
```bash
|
|
uvicorn main:app --reload
|
|
```
|
|
|
|
The application will be available at http://localhost:8000.
|
|
|
|
API documentation is available at:
|
|
- http://localhost:8000/docs (Swagger UI)
|
|
- http://localhost:8000/redoc (ReDoc)
|
|
|
|
## API Endpoints
|
|
|
|
### Todo Endpoints
|
|
|
|
- `GET /todos` - List all todos
|
|
- `POST /todos` - Create a new todo
|
|
- `GET /todos/{todo_id}` - Get a specific todo
|
|
- `PUT /todos/{todo_id}` - Update a todo
|
|
- `DELETE /todos/{todo_id}` - Delete a todo
|
|
|
|
### Health Check
|
|
|
|
- `GET /health` - Check API health
|
|
|
|
## Example Requests
|
|
|
|
### Create a Todo
|
|
|
|
```bash
|
|
curl -X 'POST' \
|
|
'http://localhost:8000/todos/' \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{
|
|
"title": "Buy groceries",
|
|
"description": "Milk, eggs, bread",
|
|
"completed": false
|
|
}'
|
|
```
|
|
|
|
### List All Todos
|
|
|
|
```bash
|
|
curl -X 'GET' 'http://localhost:8000/todos/'
|
|
```
|
|
|
|
### Update a Todo
|
|
|
|
```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
|
|
}'
|
|
``` |