Generic REST API
This is a REST API built with FastAPI and SQLite. It provides endpoints for managing items with full CRUD operations.
Features
- FastAPI framework for high performance
- SQLite database for data storage
- SQLAlchemy ORM for database interactions
- Alembic for database migrations
- Pydantic for data validation
- Automatic OpenAPI documentation
- CORS enabled
- Health check endpoint
Requirements
- Python 3.8+
- All dependencies listed in
requirements.txt
Setup
- Clone the repository
- Install dependencies:
pip install -r requirements.txt
- Set up environment variables (optional):
# Create a .env file or set these in your environment
NAME=YourNameValue
- Create and migrate database:
# The storage directory and database will be created automatically when running the app
Running the Application
Start the application with:
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
API Documentation
Once the application is running, you can access:
- Interactive API documentation: http://localhost:8000/docs
- Alternative API documentation: http://localhost:8000/redoc
- OpenAPI schema: http://localhost:8000/openapi.json
API Endpoints
GET /
: API informationGET /health
: Health check endpointGET /env/name
: Returns the value of the NAME environment variableGET /api/v1/items
: List all itemsPOST /api/v1/items
: Create a new itemGET /api/v1/items/{id}
: Get an item by IDPUT /api/v1/items/{id}
: Update an itemDELETE /api/v1/items/{id}
: Delete an item
Project Structure
.
├── alembic.ini # Alembic configuration
├── app # Application package
│ ├── api # API endpoints
│ │ └── v1 # API version 1
│ │ ├── api.py # API router setup
│ │ └── endpoints # Endpoint modules
│ │ └── items.py # Items endpoints
│ ├── core # Core application code
│ │ └── config.py # Application configuration
│ ├── crud # CRUD operations
│ │ ├── base.py # Base CRUD class
│ │ └── item.py # Item CRUD operations
│ ├── db # Database setup
│ │ ├── base.py # Base model imports
│ │ ├── base_class.py # Base model class
│ │ ├── init_db.py # Database initialization
│ │ └── session.py # Database session
│ ├── models # Database models
│ │ └── item.py # Item model
│ └── schemas # Pydantic schemas
│ └── item.py # Item schemas
├── main.py # Application entry point
├── migrations # Database migrations
│ ├── env.py # Alembic environment
│ ├── README # Migrations README
│ ├── script.py.mako # Migration script template
│ └── versions # Migration versions
└── requirements.txt # Python dependencies
Development
To lint and format the code:
ruff check .
ruff format .
Description
Languages
Python
96.5%
Mako
3.5%