Skip to content

About

REST API for task management built with Yii2, PHP 8. Features token auth, Swagger docs, CORS support.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Task Management API

Professional REST API built with Yii2 Framework

Author: Євген М.


🚀 Features

  • RESTful API with versioning (v1)
  • JWT Authentication with token-based security
  • Swagger UI documentation at /swagger/
  • CORS configured for cross-origin requests
  • MySQL/SQLite support (SQLite for easy demo)
  • Database migrations for easy deployment
  • Rate limiting for API protection
  • PSR-12 code style

📋 API Endpoints

Authentication

Method Endpoint Description
POST /api/v1/auth/register Register new user
POST /api/v1/auth/login Get JWT token
GET /api/v1/auth/me Get current user

Projects

Method Endpoint Description
GET /api/v1/projects List projects
POST /api/v1/projects Create project
GET /api/v1/projects/{id} Get project
PUT /api/v1/projects/{id} Update project
DELETE /api/v1/projects/{id} Delete project

Tasks

Method Endpoint Description
GET /api/v1/tasks List tasks
POST /api/v1/tasks Create task
GET /api/v1/tasks/{id} Get task
PUT /api/v1/tasks/{id} Update task
DELETE /api/v1/tasks/{id} Delete task
PATCH /api/v1/tasks/{id}/status Update status

⚙️ Installation

Prerequisites

  • PHP 8.1+ with extensions: curl, mbstring, openssl, pdo_sqlite (or pdo_mysql), intl
  • Composer 2.x

Quick Start

# Clone repository
cd d:\main\Project\task-management-api

# Install dependencies
composer install

# Run migrations (creates SQLite database)
php yii migrate --interactive=0

# Start development server
php -S localhost:8080 -t web/

Access


🔧 Configuration

Environment Variables (optional)

# MySQL (default: SQLite)
USE_MYSQL=true
DB_HOST=localhost
DB_PORT=3306
DB_NAME=task_api
DB_USER=root
DB_PASS=your_password

# JWT
JWT_SECRET=your-super-secret-key-256bit

MySQL Setup

CREATE DATABASE task_api CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'taskapi'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON task_api.* TO 'taskapi'@'localhost';

📖 API Usage Examples

Register User

curl -X POST http://localhost:8080/api/v1/auth/register \
  -H "Content-Type: application/json" \
  -d '{"email":"user@example.com","password":"secret123","name":"John Doe"}'

Login

curl -X POST http://localhost:8080/api/v1/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"user@example.com","password":"secret123"}'

Create Project (with token)

curl -X POST http://localhost:8080/api/v1/projects \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -d '{"name":"Website Redesign","description":"Company website project","color":"#e74c3c"}'

Create Task

curl -X POST http://localhost:8080/api/v1/tasks \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -d '{"project_id":1,"title":"Setup database","priority":"high","due_date":"2024-12-31"}'

Filter Tasks

# Get overdue tasks
curl "http://localhost:8080/api/v1/tasks?overdue=true" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

# Filter by status and priority
curl "http://localhost:8080/api/v1/tasks?status=in_progress&priority=high" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

📁 Project Structure

task-management-api/
├── components/          # Custom components (JWT, etc.)
├── config/              # Application configuration
│   ├── db.php          # Database config
│   ├── web.php         # Web app config
│   ├── console.php     # Console config
│   └── params.php      # Parameters
├── controllers/
│   ├── api/v1/         # API v1 controllers
│   │   ├── AuthController.php
│   │   ├── ProjectController.php
│   │   └── TaskController.php
│   ├── SiteController.php
│   └── SwaggerController.php
├── migrations/          # Database migrations
├── models/              # ActiveRecord models
│   ├── User.php
│   ├── Project.php
│   └── Task.php
├── runtime/             # Logs, cache, SQLite DB
├── setup/               # Installation scripts
├── web/                 # Public directory
│   └── index.php       # Entry point
├── composer.json
└── README.md

🛡️ Security Features

  • JWT tokens with configurable expiration
  • Password hashing with bcrypt
  • Rate limiting (100 requests/minute)
  • User isolation (users see only their data)
  • Input validation on all endpoints
  • SQL injection protection via ActiveRecord

📄 License

MIT License - Євген М. 2026

About

REST API for task management built with Yii2, PHP 8. Features token auth, Swagger docs, CORS support.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages