PHPackages                             yunusbek/adaptive-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. yunusbek/adaptive-api

ActiveLibrary[API Development](/categories/api)

yunusbek/adaptive-api
=====================

Adaptive API package for Yii2 projects

v1.0.292(2mo ago)040MITPHP

Since Sep 30Pushed 2mo agoCompare

[ Source](https://github.com/yunusbek9669/adaptive-api)[ Packagist](https://packagist.org/packages/yunusbek/adaptive-api)[ RSS](/packages/yunusbek-adaptive-api/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (32)Used By (0)

Adaptive API
============

[](#adaptive-api)

Adaptive API package features

> ✅ Dynamically generate custom API structures based on client requirements
> ✅ Allow clients to fetch data with dynamic filtering options
> ✅ Retrieve only the required tables and columns from the database
> ✅ Access all database tables through a single API endpoint (one unified URL).
> – Clients send the desired table structures in the request body, and the API returns exactly what is requested

Installation
------------

[](#installation)

Either run

```
composer require yunusbek/adaptive-api
```

or add

```
"yunusbek/adaptive-api": "^1.0",
```

to the `require` section of your composer.json.

Installation
------------

[](#installation-1)

1. Create `.env` file in the root of your application:

```
API_DB_ROLE=api_reader
API_DB_USER=api_user_api
API_DB_PASSWORD=_p@$$word_
#API_DB_HOST=localhost
#API_DB_NAME=your-dbname
#API_DB_PORT=5432
UPLOAD_FOLDER_PATH=/uploads/
```

2. Load `.env` inside `web/index.php` and root `yii` file:

```
#...
$dotenv = Dotenv\Dotenv::createUnsafeMutable(dirname(__DIR__.'/../.env'));
$dotenv->load();
#...
```

3. Run migration to create the `api_user` database user and apply permissions:

```
php yii migrate --migrationPath=@vendor/yunusbek/adaptive-api/src/migrations
```

```
# Add the following code to controllerMap
[
    #...
    'controllerMap' => [
        'api-schema-migration' => 'Yunusbek\AdaptiveApi\commands\Migrations',
    ],
    #...
]
```

The next thing you need to do is updating your database schema by applying the migration of table `client_api_schema_permissions`:

```
php yii api-schema-migration
```

Example to permission schema

table - client\_api\_schema\_permissions
========================================

[](#table---client_api_schema_permissions)

column - schema:jsonb
=====================

[](#column---schemajsonb)

```
{
  "{user}": {
    "username": "",
    "email": "",
    "phone": "",
    "address": ""
  },
  "{company}": {
    "company_name": "",
    "email": "",
    "phone": "",
    "address": ""
  }
}
```

Usage
-----

[](#usage)

Example to api request structure

```
{
  "customer": {
    "personal_info": {
      "person": "{user}.username",
      "email": "{user}.email",
      "gender": "{user}.gender",
      "age": "TO_CHAR(TO_TIMESTAMP({user}.age), 'DD.MM.YYYY')",
      "personal_phone": "{user}.phone",
      "personal_address": "{user}.address"
    },
    "company_info": {
      "company": "{company}.company_name",
      "company_email": "{company}.email",
      "company_phone": "{company}.phone",
      "company_address": "{company}.address"
    },
    "position_info": {
      "user_department": "{position}.department",
      "user_position": "{position}.name",
      "product_info": {
        "product_name": "{product}.name",
        "product_type": "{product}.type",
        "product_cost": "{product}.cost"
      }
    }
  }
}
```

result

```
{
  "customer": {
    "personal_info": {
      "person": "John Doe",
      "email": "johndoe@example.com",
      "gender": "male",
      "personal_phone": "+9989********",
      "personal_address": "Some address data"
    },
    "company_info": {
      "company": "Example LLC",
      "company_email": "example@example.com",
      "company_phone": "+9989********",
      "company_address": "Some address data"
    },
    "position_info": {
      "user_department": "Sales department",
      "user_position": "seller",
      "product_info": {
        "product_name": "Bicycle",
        "product_type": "Sport",
        "product_cost": "$33.5"
      }
    }
  }
}
```

---

```
$root = [
    'unique_number' => 'user_id',
    'select' => [
        "user_id",
        "position_id",
        "company_id",
        "product_id" => "product.id",
        "started_date",
        "status",
    ],
    'class' => UserRelCompany::class, // or by table name 'table' => 'user_rel_company'
    'join' => [
        ['JOIN', "products AS product", 'on' => ["user_id" => "user_id"], 'condition' => ['status' => 'ACTIVE']]
    ],
    'where' => [
        'current_company' => true,
        'product.type' => ['building', 'food', 'sport']
    ],
    'filter' => [
        'product_type' => "product.type",
    ]
];

$relations = [
    'user' => [
        'on' => ["id" => "user_id"],
        'class' => Users::class // or users_table_name,
        'select' => [
            "username",
            "email",
            "gender",
            "phone",
            "address",
        ],
        'where' => [
            'status' => 'ACTIVE'
        ]
    ],
    'company' => [
        'on' => ["id" => "company_id"],
        'class' => Companies::class // or companies_table_name,
        'select' => [
            "company_name" => 'name',
            "email",
            "phone",
            "address",
        ],
        'where' => [
            'status' => 'ACTIVE'
        ]
    ],
    'position' => [
        'on' => ["id" => "position_id"],
        'class' => UserStaffPosition::class,
        'select' => [
            "name",
            "department",
        ],
        'where' => [
            'status' => 'ACTIVE'
        ]
    ],
    'product' => [
        'on' => ["id" => "product_id"],
        'class' => Products::class // or products_table_name,
        'select' => [
            "name",
            "type",
            "cost",
        ],
        'where' => [
            'status' => 'ACTIVE'
        ]
    ],
    #... other relations tables
];
$response = CteBuilder::root($root) // root table
    ->relation($relations)          // relation tables
    ->with($with)                   // if you need with cte
    ->queryParams($params)          // GET query string params (client request)
    ->template($sendTemplate)       // body params (client request structure)
//    ->setCallback(function (string $text, string $lang) use ($params) {           // this is optional if you want to add some callback function
//        if ($lang === 'en') { $lang = 'ru'; }
//        return KirillToLatin::widget(['text' => $text, 'lang' => $lang]);
//    }, '/^\{(uz|ru|en)\}(.*)/')
    ->getApi();                     // finish
```

---

📘 `/reference` API
==================

[](#-reference-api)

**Method:** `POST`
**Description:**
This endpoint returns reference data from related tables using dynamic field selection and alias-based filtering.
It supports both pagination (`count`) and relation field filters (e.g. `code=av`).

---

🧩 Request Parameters
--------------------

[](#-request-parameters)

### 🔹 Query Parameters

[](#-query-parameters)

NameRequiredvalueDescription`count`❌`4`The number of records to return. Example: `4``attribute_name`❌`11` or `[11,15,22]`Filter applied to the related table `{alias}.attribute_name`. Example: `attribute_name=11` or `attribute_name in (11,15,22)``attribute_name`❌`2234` or `[2234,2264,2431]`Filter applied to the related table `{relatedAlias}.attribute_name`. Example: `attribute_name=2234` or `attribute_name in (2234,2264,2431)`> 📝 **Note:**
> The `` prefix indicates that the field belongs to a related (joined) table or alias.

---

### 🔹 Request Body (JSON)

[](#-request-body-json)

FieldRequiredDescription`users`✅Pattern for selecting fields from the `users` CTE/table. `{users}.*` means “select all columns.”`department`✅Pattern for including all fields from the related `department` table or CTE. `.*` means “include all columns.”#### Example:

[](#example)

```
{
  "users": "{users}.*",
  "department": ".*"
}
```

### 🧾 Example Request

[](#-example-request)

```
GET /reference?count=4&code=av
```

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance83

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~5 days

Recently: every ~32 days

Total

31

Last Release

87d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/70483ac992f0451b37284d0b2f31c76ebe7bf032fb522f42b10b40b8a240f21b?d=identicon)[yunusbek9669](/maintainers/yunusbek9669)

### Embed Badge

![Health badge](/badges/yunusbek-adaptive-api/health.svg)

```
[![Health](https://phpackages.com/badges/yunusbek-adaptive-api/health.svg)](https://phpackages.com/packages/yunusbek-adaptive-api)
```

###  Alternatives

[showdoc/showdoc

ShowDoc is a tool greatly applicable for an IT team to share documents online

12.8k7.0k](/packages/showdoc-showdoc)[netflie/whatsapp-cloud-api

The first PHP SDK to send and receive messages using a cloud-hosted version of the WhatsApp Business Platform

640431.7k4](/packages/netflie-whatsapp-cloud-api)[wrav/oembed

A simple plugin to extract media information from websites, like youtube videos, twitter statuses or blog articles.

36205.0k3](/packages/wrav-oembed)[jasara/php-amzn-selling-partner-api

A fluent interface for Amazon's Selling Partner API in PHP

1344.8k1](/packages/jasara-php-amzn-selling-partner-api)[hardcastle/xrpl_php

PHP SDK / Client for the XRP Ledger

129.7k5](/packages/hardcastle-xrpl-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
