uptura-official/flexiapi
Composer 安装命令:
composer require uptura-official/flexiapi
包简介
FlexiAPI - A powerful CLI-based framework for rapid REST API development with zero configuration
README 文档
README
FlexiAPI is a powerful, zero-configuration CLI framework for rapid REST API development. Build production-ready APIs with authentication, encryption, pagination, and CORS in minutes, not hours.
🌟 Key Features
- 🎯 Zero Configuration - Get started immediately without complex setup
- 🔐 Built-in Authentication - JWT with custom headers (Auth-x)
- 🛡️ Field-Level Encryption - AES-256-CBC encryption for sensitive data
- 📊 Advanced Querying - Pagination, search, filtering, and sorting
- 🌐 Dynamic CORS - CLI-configurable CORS policies
- ⚡ Rapid Development - Create full CRUD APIs in seconds
- 🔧 Flexible CLI - Works in development and production environments
- 📦 Easy Deployment - Composer-ready package management
📦 Installation
Global Installation (User Recommended)
composer global require uptura-official/flexiapi mkdir my-api && cd my-api flexiapi init
Create New Project (Developers)
composer create-project uptura-official/flexiapi
cd flexiapi
flexiapi setup
Create with Custom Directory Name
composer create-project uptura-official/flexiapi . # Run this inside your desired project directory
Manual Setup
git clone https://github.com/Uptura/flexiapi.git my-api-project
cd my-api-project
composer install
flexiapi setup
Local Dev Test
php bin/flexiapi --command
Update Framework
composer update uptura-official/flexiapi --no-cache
🚀 Quick Start
1. Initialize Your API
flexiapi setup
# Configures database, authentication, and basic settings
2. Create Your First Endpoint
flexiapi create users
# Interactive setup: define columns, data types, encryption
3. Start Development Server
flexiapi serve
# Launches built-in development server with your API
4. Test Your API
Your API is immediately available with full CRUD operations:
# List all users (with pagination) curl -H "Auth-x: Bearer YOUR_TOKEN" http://localhost:8000/api/v1/users # Create a new user curl -X POST -H "Auth-x: Bearer YOUR_TOKEN" \ -H "Content-Type: application/json" \ -d '{"name":"John Doe","email":"john@example.com"}' \ http://localhost:8000/api/v1/users # Get specific user curl -H "Auth-x: Bearer YOUR_TOKEN" http://localhost:8000/api/v1/users/1 # Update user curl -X PUT -H "Auth-x: Bearer YOUR_TOKEN" \ -H "Content-Type: application/json" \ -d '{"name":"Jane Doe"}' \ http://localhost:8000/api/v1/users/1 # Delete user curl -X DELETE -H "Auth-x: Bearer YOUR_TOKEN" http://localhost:8000/api/v1/users/1
🔐 Authentication
FlexiAPI uses JWT tokens with a custom Auth-x header for enhanced security.
Generate API Keys
curl -X POST http://localhost:8000/api/v1/auth/generate_keys
To solve "Invalid secret", retrieve your JWT secret key from config.php
Response:
{
"success": true,
"message": "API keys generated successfully",
"data": {
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
"expires_at": "2025-10-11 22:00:00"
}
}
Use Authentication
Include the Auth-x header in all authenticated requests:
curl -H "Auth-x: Bearer YOUR_TOKEN" http://localhost:8000/api/v1/users
🛡️ Field-Level Encryption
Protect sensitive data with built-in AES-256-CBC encryption.
Configure Encryption
flexiapi update:endpoint users
# Choose option to configure field encryption
Automatic Encryption/Decryption
# Create user with encrypted field curl -X POST -H "Auth-x: Bearer YOUR_TOKEN" \ -H "Content-Type: application/json" \ -d '{"name":"John","ssn":"123-45-6789"}' \ http://localhost:8000/api/v1/users # SSN is automatically encrypted in database # SSN is automatically decrypted in API responses
📊 Advanced Querying
Pagination
# Get page 2 with 10 items per page curl -H "Auth-x: Bearer TOKEN" \ "http://localhost:8000/api/v1/users?page=2&limit=10"
Search Across All Fields
# Search for "john" across all searchable fields curl -H "Auth-x: Bearer TOKEN" \ "http://localhost:8000/api/v1/users?search=john"
Column-Specific Search
# Search by specific column curl -H "Auth-x: Bearer TOKEN" \ "http://localhost:8000/api/v1/users/search/email?q=gmail.com"
Sorting
# Sort by name ascending curl -H "Auth-x: Bearer TOKEN" \ "http://localhost:8000/api/v1/users?sort=name&order=ASC"
Combined Queries
# Complex query: search + pagination + sorting curl -H "Auth-x: Bearer TOKEN" \ "http://localhost:8000/api/v1/users?search=john&page=1&limit=5&sort=created_at&order=DESC"
Response Format
{
"success": true,
"message": "Records retrieved successfully",
"data": [
{
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"created_at": "2025-10-10 12:00:00"
}
],
"pagination": {
"page": 1,
"limit": 10,
"total": 25,
"pages": 3
}
}
🌐 CORS Configuration
Configure CORS policies dynamically via CLI.
Interactive CORS Setup
flexiapi configure:cors
# Guides you through origins, methods, headers, and credentials
Example CORS Configuration
Origins: https://yourdomain.com, https://app.yourdomain.com
Methods: GET, POST, PUT, DELETE, OPTIONS
Headers: Content-Type, Authorization, Auth-x
Credentials: true
Max Age: 86400 seconds
🔧 CLI Commands
Core Commands
flexiapi setup # Initial framework configuration flexiapi create:endpoint <name> # Create new API endpoint flexiapi update:endpoint <name> # Modify existing endpoint flexiapi list:endpoints # Show all endpoints flexiapi configure:cors # Configure CORS policy flexiapi serve [--port=8000] # Start development server
Generation Commands
flexiapi generate:postman # Generate Postman collection flexiapi export:sql # Export unified SQL schema
Aliases
flexiapi create users # Same as create:endpoint users flexiapi update users # Same as update:endpoint users flexiapi list # Same as list:endpoints flexiapi cors # Same as configure:cors flexiapi serve # Start development server
📁 Project Structure
your-api/
├── config/
│ ├── config.php # Database & app configuration
│ └── cors.php # CORS policy settings
├── endpoints/
│ ├── UsersController.php # Generated endpoint controllers
│ └── usersRoutes.php # Generated route definitions
├── sql/
│ ├── users.sql # Individual table schemas
│ └── products.sql
├── exports/
│ └── FlexiAPI_Schema_Latest.sql # Unified schema export
├── public/
│ └── index.php # API entry point
├── storage/
│ ├── logs/ # Application logs
│ └── cache/ # Rate limiting cache
├── Procfile # Heroku deployment config
├── .nixpacks.toml # Railway/Nixpacks deployment config
├── app.json # Heroku Button configuration
└── .platform.app.yaml # Platform.sh deployment config
🔄 API Response Format
All API responses follow a consistent format:
Success Response
{
"success": true,
"message": "Operation completed successfully",
"data": {
"id": 1,
"name": "John Doe"
}
}
Error Response
{
"success": false,
"message": "Validation failed",
"errors": {
"email": "Email is required"
}
}
Paginated Response
{
"success": true,
"message": "Records retrieved successfully",
"data": [...],
"pagination": {
"page": 1,
"limit": 10,
"total": 100,
"pages": 10
}
}
🛠️ Development Workflow
1. Create New Feature Endpoint
flexiapi create:endpoint products # Define columns: name, price, description # Configure encryption for sensitive pricing data
2. Update Existing Endpoint
flexiapi update:endpoint products
# Add columns, modify types, configure encryption
3. Test API Endpoints
flexiapi generate:postman
# Creates ready-to-use Postman collection
4. Export Database Schema
flexiapi export:sql
# Creates unified SQL file for deployment
🚀 Deployment
Platform as a Service (PaaS) - One-Click Deploy
Heroku
FlexiAPI includes a Procfile for seamless Heroku deployment:
web: php -S 0.0.0.0:$PORT -t public
Railway
FlexiAPI includes .nixpacks.toml for Railway's Nixpacks builder:
[start] cmd = "php -S 0.0.0.0:8080 -t /app/public"
Deploy steps:
# Connect your GitHub repo to Railway # Railway auto-detects .nixpacks.toml and Procfile # Deploys automatically
Platform.sh
Includes .platform.app.yaml for Platform.sh deployment.
Traditional Server Setup
- Create new project:
composer create-project uptura-official/flexiapi my-api-project
cd my-api-project
- Configure production database:
flexiapi setup
# Enter production database credentials
- Create endpoints and export schema:
flexiapi create users flexiapi export:sql
- Upload to server and import database:
mysql -u user -p database < exports/FlexiAPI_Schema_Latest.sql
Environment Variables
Set these variables for production deployment:
DB_HOST=your_db_host DB_DATABASE=your_db_name DB_USERNAME=your_db_user DB_PASSWORD=your_db_password JWT_SECRET=your_jwt_secret API_SECRET=your_api_secret
🤝 Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Setup
git clone https://github.com/Uptura/flexiapi.git
cd flexiapi
composer install
flexiapi setup
📄 License
FlexiAPI is open-sourced software licensed under the MIT license.
🔗 Links
- 📖 Documentation
- 🐛 Issues
- 💬 Discussions
- 🌟 Changelog
💡 Support
- Documentation: Full guides and examples in this README
- Issues: Report bugs on GitHub Issues
- Community: Join discussions on GitHub Discussions
Made with ❤️ by Uptura
- ✅ Postman collection generation
- ✅ SQL export functionality
uptura-official/flexiapi 适用场景与选型建议
uptura-official/flexiapi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 98 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 10 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「rest」 「api」 「cli」 「mysql」 「crud」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 uptura-official/flexiapi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 uptura-official/flexiapi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 uptura-official/flexiapi 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
A Flickr wrapper to allow you to call the Flickr api with Guzzle as the backend.Goal is to have 100% Flickr api coverage rather than just upload/display photos (currently at 23%).
High-performance, opinionated PHP 8 web framework with O(1) routing, parallel async MySQL, type-safe asset bridge, and React-island frontend
BlockCypher's PHP SDK for REST API
统计信息
- 总下载量: 98
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-10