Automated Action f2d3f2d55c Create FastAPI REST API with Python and SQLite
- Implemented user authentication with JWT
- Added CRUD operations for users and items
- Setup database connection with SQLAlchemy
- Added migration scripts for easy database setup
- Included health check endpoint for monitoring

generated with BackendIM... (backend.im)
2025-05-13 18:33:54 +00:00

89 lines
2.3 KiB
Markdown

# Generic REST API Service
A generic REST API service built with FastAPI and SQLite, providing endpoints for user management and item operations.
## Features
- User management (registration, authentication, profile management)
- JWT-based authentication
- Item CRUD operations
- Database migrations with Alembic
- Comprehensive API documentation
- Health check endpoint
## Project Structure
```
├── app/
│ ├── database/ # Database connection and session management
│ ├── models/ # SQLAlchemy ORM models
│ ├── routes/ # API route definitions
│ ├── schemas/ # Pydantic schemas for request/response validation
│ ├── utils/ # Utility functions
│ └── storage/ # Storage for database and files
├── migrations/ # Alembic migration scripts
├── alembic.ini # Alembic configuration
├── main.py # Application entry point
└── requirements.txt # Project dependencies
```
## Setup
1. Clone the repository
2. Install dependencies:
```bash
pip install -r requirements.txt
```
3. Run the application:
```bash
uvicorn main:app --reload
```
## API Documentation
Once the application is running, you can access the automatically generated API documentation at:
- Swagger UI: `http://localhost:8000/docs`
- ReDoc: `http://localhost:8000/redoc`
## Available Endpoints
### Authentication
- `POST /api/v1/users/token` - Login and get access token
### Users
- `POST /api/v1/users/` - Register a new user
- `GET /api/v1/users/me` - Get current user profile
- `PUT /api/v1/users/me` - Update current user profile
- `GET /api/v1/users/` - List all users (requires authentication)
- `GET /api/v1/users/{user_id}` - Get user by ID (requires authentication)
### Items
- `POST /api/v1/items/` - Create a new item (requires authentication)
- `GET /api/v1/items/` - List all items (requires authentication)
- `GET /api/v1/items/my-items` - List all items owned by current user (requires authentication)
- `GET /api/v1/items/{item_id}` - Get item by ID (requires authentication)
- `PUT /api/v1/items/{item_id}` - Update item (requires ownership)
- `DELETE /api/v1/items/{item_id}` - Delete item (requires ownership)
### Health Check
- `GET /health` - API health status
## Database Migrations
To apply migrations:
```bash
alembic upgrade head
```
## License
MIT