
- Set up project structure with FastAPI - Create SQLite database with SQLAlchemy - Implement Alembic for database migrations - Add CRUD operations for items resource - Create health endpoint - Update documentation generated with BackendIM... (backend.im)
1.9 KiB
1.9 KiB
Generic REST API
A RESTful API built with FastAPI and SQLAlchemy.
Features
- FastAPI for high-performance API with automatic OpenAPI documentation
- SQLAlchemy ORM for database operations
- SQLite database for storage
- Alembic for database migrations
- Pydantic models for request/response validation
- CRUD operations for the 'items' resource
- Health check endpoint
Project Structure
├── alembic/ # Database migration scripts
├── app/ # Application source code
│ ├── api/ # API endpoints
│ │ ├── endpoints/ # API routes
│ ├── crud/ # CRUD operations
│ ├── db/ # Database configurations
│ ├── models/ # SQLAlchemy models
│ └── schemas/ # Pydantic schemas
├── storage/ # Storage directory
│ └── db/ # Database files
├── alembic.ini # Alembic configuration
├── main.py # Application entry point
└── requirements.txt # Project dependencies
Installation and Setup
-
Clone the repository
-
Install the dependencies:
pip install -r requirements.txt
-
Apply the database migrations:
alembic upgrade head
-
Run the application:
uvicorn main:app --reload
API Documentation
Once the application is running, you can access the API documentation at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
API Endpoints
Items Resource
GET /items
: Get all items (paginated)POST /items
: Create a new itemGET /items/{item_id}
: Get a specific item by IDPUT /items/{item_id}
: Update an itemDELETE /items/{item_id}
: Delete an item
Health Check
GET /health
: Check API health status