Automated Action a4ffe78f61 Create REST API with FastAPI and SQLAlchemy
- 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)
2025-05-14 10:26:10 +00:00

71 lines
1.9 KiB
Markdown

# 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
1. Clone the repository
2. Install the dependencies:
```bash
pip install -r requirements.txt
```
3. Apply the database migrations:
```bash
alembic upgrade head
```
4. Run the application:
```bash
uvicorn main:app --reload
```
## API Documentation
Once the application is running, you can access the API documentation at:
- Swagger UI: [http://localhost:8000/docs](http://localhost:8000/docs)
- ReDoc: [http://localhost:8000/redoc](http://localhost:8000/redoc)
## API Endpoints
### Items Resource
- `GET /items`: Get all items (paginated)
- `POST /items`: Create a new item
- `GET /items/{item_id}`: Get a specific item by ID
- `PUT /items/{item_id}`: Update an item
- `DELETE /items/{item_id}`: Delete an item
### Health Check
- `GET /health`: Check API health status