FlexiAPI - A powerful CLI-based framework for rapid REST API development with zero configuration

Installs: 93

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/uptura-official/flexiapi

v3.7.25 2025-10-26 13:51 UTC

README

Latest Version PHP Version License

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

Deploy to 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

  1. Create new project:
composer create-project uptura-official/flexiapi my-api-project
cd my-api-project
  1. Configure production database:
flexiapi setup
# Enter production database credentials
  1. Create endpoints and export schema:
flexiapi create users
flexiapi export:sql
  1. 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

💡 Support

Made with ❤️ by Uptura

  • ✅ Postman collection generation
  • ✅ SQL export functionality