
- 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)
2.3 KiB
2.3 KiB
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
- Clone the repository
- Install dependencies:
pip install -r requirements.txt
- Run the application:
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 userGET /api/v1/users/me
- Get current user profilePUT /api/v1/users/me
- Update current user profileGET /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:
alembic upgrade head
License
MIT