
- Set up project structure with FastAPI - Configure SQLite database with SQLAlchemy - Set up Alembic for migrations - Create Item model and schema - Implement CRUD operations - Add health endpoint generated with BackendIM... (backend.im)
2.0 KiB
2.0 KiB
Generic REST API Service
A RESTful API service built with FastAPI and SQLite database.
Features
- FastAPI framework with automatic Swagger/ReDoc documentation
- SQLAlchemy ORM for database management
- Alembic for database migrations
- SQLite database
- Pydantic models for data validation
- CRUD operations for resources
- Health check endpoint
Project Structure
.
├── alembic/ # Database migration scripts
├── app/ # Application code
│ ├── api/ # API endpoints
│ │ └── v1/ # API version 1
│ ├── core/ # Core functionality
│ ├── crud/ # CRUD operations
│ ├── db/ # Database setup
│ ├── models/ # SQLAlchemy models
│ └── schemas/ # Pydantic schemas
├── alembic.ini # Alembic configuration
├── main.py # Application entry point
└── requirements.txt # Project dependencies
Installation
- Clone the repository:
git clone <repository-url>
cd genericrestapiservice
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Run database migrations:
alembic upgrade head
Running the Application
Start the application using Uvicorn:
uvicorn main:app --reload
The API will be available at http://localhost:8000
Documentation is available at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
API Endpoints
Health Check
GET /api/v1/health
: Check API health
Items Resource
GET /api/v1/items
: List all itemsPOST /api/v1/items
: Create a new itemGET /api/v1/items/{id}
: Get a specific itemPUT /api/v1/items/{id}
: Update an itemDELETE /api/v1/items/{id}
: Delete an item