147 lines
5.0 KiB
Markdown
147 lines
5.0 KiB
Markdown
# Task Manager API
|
|
|
|
A robust RESTful API for managing tasks, built with FastAPI and SQLite.
|
|
|
|
## Features
|
|
|
|
- **User Authentication**: Secure registration and login with JWT tokens
|
|
- **Task Management**: Complete CRUD operations for tasks
|
|
- **Task Filtering**: Filter tasks by status, priority, and search terms
|
|
- **Health Monitoring**: Endpoint for application health checking
|
|
- **API Documentation**: Interactive documentation with Swagger UI and ReDoc
|
|
- **Database Migrations**: Easy database schema management with Alembic
|
|
|
|
## Tech Stack
|
|
|
|
- **FastAPI**: Modern, fast web framework for building APIs
|
|
- **SQLAlchemy**: SQL toolkit and ORM
|
|
- **Alembic**: Database migration tool
|
|
- **Pydantic**: Data validation and settings management
|
|
- **SQLite**: Lightweight, file-based database
|
|
- **JWT**: JSON Web Tokens for secure authentication
|
|
- **Ruff**: Fast Python linter for code quality
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
task-manager-api/
|
|
├── alembic.ini # Alembic configuration
|
|
├── main.py # Application entry point
|
|
├── pyproject.toml # Project configuration
|
|
├── requirements.txt # Project dependencies
|
|
├── app/ # Application package
|
|
│ ├── api/ # API endpoints
|
|
│ │ ├── deps.py # API dependencies
|
|
│ │ └── v1/ # API version 1
|
|
│ │ ├── api.py # API router
|
|
│ │ └── endpoints/ # API endpoint modules
|
|
│ │ ├── auth.py # Authentication endpoints
|
|
│ │ ├── tasks.py # Task management endpoints
|
|
│ │ └── users.py # User management endpoints
|
|
│ ├── core/ # Core modules
|
|
│ │ ├── config.py # Application configuration
|
|
│ │ └── security.py # Security utilities
|
|
│ ├── crud/ # CRUD operations
|
|
│ │ ├── base.py # Base CRUD class
|
|
│ │ ├── task.py # Task CRUD operations
|
|
│ │ └── user.py # User CRUD operations
|
|
│ ├── db/ # Database configuration
|
|
│ │ └── database.py # Database setup
|
|
│ ├── models/ # SQLAlchemy models
|
|
│ │ ├── task.py # Task model
|
|
│ │ └── user.py # User model
|
|
│ └── schemas/ # Pydantic schemas
|
|
│ ├── task.py # Task schemas
|
|
│ └── user.py # User schemas
|
|
└── migrations/ # Alembic migrations
|
|
├── env.py # Alembic environment
|
|
├── script.py.mako # Alembic script template
|
|
└── versions/ # Migration versions
|
|
```
|
|
|
|
## Installation
|
|
|
|
1. Clone the repository:
|
|
```bash
|
|
git clone <repository-url>
|
|
cd task-manager-api
|
|
```
|
|
|
|
2. Install dependencies:
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
3. Run database migrations:
|
|
```bash
|
|
alembic upgrade head
|
|
```
|
|
|
|
4. Start the application:
|
|
```bash
|
|
uvicorn main:app --reload
|
|
```
|
|
|
|
## API Documentation
|
|
|
|
Once the application is running, you can access:
|
|
- Swagger UI: http://localhost:8000/docs
|
|
- ReDoc: http://localhost:8000/redoc
|
|
- OpenAPI Schema: http://localhost:8000/openapi.json
|
|
|
|
## Environment Variables
|
|
|
|
The application uses the following environment variables:
|
|
|
|
- `SECRET_KEY`: Secret key for JWT tokens (default: "changethisinproduction")
|
|
- `ACCESS_TOKEN_EXPIRE_MINUTES`: Token expiration time in minutes (default: 30)
|
|
- `API_V1_STR`: API version prefix (default: "/api/v1")
|
|
|
|
## Usage Examples
|
|
|
|
### Authentication
|
|
|
|
```bash
|
|
# Register a new user
|
|
curl -X POST "http://localhost:8000/api/v1/auth/register" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"email": "user@example.com", "username": "testuser", "password": "Password123"}'
|
|
|
|
# Login and get access token
|
|
curl -X POST "http://localhost:8000/api/v1/auth/login" \
|
|
-H "Content-Type: application/x-www-form-urlencoded" \
|
|
-d "username=user@example.com&password=Password123"
|
|
```
|
|
|
|
### Task Management
|
|
|
|
```bash
|
|
# Create a new task (requires authentication)
|
|
curl -X POST "http://localhost:8000/api/v1/tasks" \
|
|
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"title": "Complete project", "description": "Finish the API project", "priority": "high", "due_date": "2023-12-31T23:59:59"}'
|
|
|
|
# Get all tasks
|
|
curl -X GET "http://localhost:8000/api/v1/tasks" \
|
|
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
|
|
|
|
# Get a specific task
|
|
curl -X GET "http://localhost:8000/api/v1/tasks/1" \
|
|
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
|
|
|
|
# Update a task
|
|
curl -X PUT "http://localhost:8000/api/v1/tasks/1" \
|
|
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"status": "in_progress"}'
|
|
|
|
# Delete a task
|
|
curl -X DELETE "http://localhost:8000/api/v1/tasks/1" \
|
|
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
|
|
```
|
|
|
|
## License
|
|
|
|
This project is licensed under the MIT License - see the LICENSE file for details.
|