
- Set up project structure with FastAPI app - Implement SQLAlchemy models and async database connection - Create CRUD endpoints for items resource - Add health endpoint for monitoring - Configure Alembic for database migrations - Create comprehensive documentation generated with BackendIM... (backend.im)
1.6 KiB
1.6 KiB
Generic REST API Service
A RESTful API service built with FastAPI and SQLite for database storage.
Features
- RESTful API endpoints for CRUD operations on items
- Async SQLAlchemy with SQLite database
- Database migrations with Alembic
- Health check endpoint
- Pydantic schemas for validation
- Comprehensive API documentation
Project Structure
├── alembic/ # Database migration files
├── app/ # Application package
│ ├── api/ # API endpoints and routes
│ ├── db/ # Database connection and utilities
│ ├── models/ # SQLAlchemy ORM models
│ └── schemas/ # Pydantic schemas for validation and serialization
├── main.py # Application entry point
├── requirements.txt # Project dependencies
└── README.md # This file
API Endpoints
GET /health
: Check API health statusGET /api/items
: List all itemsGET /api/items/{item_id}
: Get a specific itemPOST /api/items
: Create a new itemPUT /api/items/{item_id}
: Update an existing itemDELETE /api/items/{item_id}
: Delete an item
Getting Started
-
Install dependencies:
pip install -r requirements.txt
-
Run the application:
uvicorn main:app --reload
-
Access the API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Database Migrations
Database migrations are managed with Alembic:
# Apply migrations
alembic upgrade head
# Create a new migration
alembic revision --autogenerate -m "description"