
- Set up project structure with FastAPI app - Implement items CRUD API endpoints - Configure SQLite database with SQLAlchemy - Set up Alembic migrations - Add health check endpoint - Enable CORS middleware - Create README with documentation
127 lines
2.5 KiB
Markdown
127 lines
2.5 KiB
Markdown
# Quick API Service
|
|
|
|
A simple FastAPI application that provides a quick working API with basic CRUD operations.
|
|
|
|
## Features
|
|
|
|
- RESTful API with FastAPI
|
|
- SQLite database with SQLAlchemy ORM
|
|
- Alembic migrations for database versioning
|
|
- CORS middleware enabled
|
|
- Health check endpoint
|
|
- Swagger documentation at `/docs`
|
|
- ReDoc documentation at `/redoc`
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
.
|
|
├── app
|
|
│ ├── api
|
|
│ │ └── v1
|
|
│ │ ├── api.py
|
|
│ │ └── endpoints
|
|
│ │ └── items.py
|
|
│ ├── core
|
|
│ │ └── config.py
|
|
│ ├── crud
|
|
│ │ └── item.py
|
|
│ ├── db
|
|
│ │ ├── base.py
|
|
│ │ └── session.py
|
|
│ ├── models
|
|
│ │ └── item.py
|
|
│ ├── schemas
|
|
│ │ └── item.py
|
|
│ └── storage
|
|
│ └── db
|
|
├── migrations
|
|
│ ├── env.py
|
|
│ ├── README
|
|
│ ├── script.py.mako
|
|
│ └── versions
|
|
│ └── 53b8c3f67ecb_create_items_table.py
|
|
├── alembic.ini
|
|
├── main.py
|
|
├── README.md
|
|
└── requirements.txt
|
|
```
|
|
|
|
## Installation
|
|
|
|
1. Clone the repository:
|
|
|
|
```bash
|
|
git clone <repository-url>
|
|
cd quickapiservice
|
|
```
|
|
|
|
2. Install dependencies:
|
|
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
3. Run the migrations:
|
|
|
|
```bash
|
|
alembic upgrade head
|
|
```
|
|
|
|
4. Start the application:
|
|
|
|
```bash
|
|
uvicorn main:app --reload
|
|
```
|
|
|
|
The API will be available at http://localhost:8000
|
|
|
|
## API Endpoints
|
|
|
|
- `GET /`: Root endpoint with basic information
|
|
- `GET /health`: Health check endpoint
|
|
- `GET /docs`: Swagger documentation
|
|
- `GET /redoc`: ReDoc documentation
|
|
|
|
### Items API
|
|
|
|
- `GET /api/v1/items`: Get all items
|
|
- `POST /api/v1/items`: Create a new item
|
|
- `GET /api/v1/items/{item_id}`: Get an item by ID
|
|
- `PUT /api/v1/items/{item_id}`: Update an item
|
|
- `DELETE /api/v1/items/{item_id}`: Delete an item
|
|
|
|
## Example API Usage
|
|
|
|
### Create an Item
|
|
|
|
```bash
|
|
curl -X 'POST' \
|
|
'http://localhost:8000/api/v1/items/' \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{
|
|
"title": "Example Item",
|
|
"description": "This is an example item"
|
|
}'
|
|
```
|
|
|
|
### Get All Items
|
|
|
|
```bash
|
|
curl -X 'GET' 'http://localhost:8000/api/v1/items/'
|
|
```
|
|
|
|
## Development
|
|
|
|
The application uses SQLite for the database, which is stored at `/app/storage/db/db.sqlite`.
|
|
|
|
To apply new migrations:
|
|
|
|
```bash
|
|
alembic revision --autogenerate -m "description"
|
|
alembic upgrade head
|
|
```
|
|
|
|
## License
|
|
|
|
This project is licensed under the MIT License. |