
- 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)
87 lines
2.0 KiB
Markdown
87 lines
2.0 KiB
Markdown
# 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
|
|
|
|
1. Clone the repository:
|
|
|
|
```bash
|
|
git clone <repository-url>
|
|
cd genericrestapiservice
|
|
```
|
|
|
|
2. Create a virtual environment:
|
|
|
|
```bash
|
|
python -m venv venv
|
|
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
```
|
|
|
|
3. Install dependencies:
|
|
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
4. Run database migrations:
|
|
|
|
```bash
|
|
alembic upgrade head
|
|
```
|
|
|
|
## Running the Application
|
|
|
|
Start the application using Uvicorn:
|
|
|
|
```bash
|
|
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 items
|
|
- `POST /api/v1/items`: Create a new item
|
|
- `GET /api/v1/items/{id}`: Get a specific item
|
|
- `PUT /api/v1/items/{id}`: Update an item
|
|
- `DELETE /api/v1/items/{id}`: Delete an item |