PHPackages                             wdmg/yii2-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. wdmg/yii2-api

ActiveYii2-extension[API Development](/categories/api)

wdmg/yii2-api
=============

API control module

2.0.1(2y ago)254421MITPHP

Since May 25Pushed 2y ago3 watchersCompare

[ Source](https://github.com/wdmg/yii2-api)[ Packagist](https://packagist.org/packages/wdmg/yii2-api)[ Docs](https://github.com/wdmg/yii2-api)[ RSS](/packages/wdmg-yii2-api/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (6)Dependencies (7)Versions (38)Used By (1)

[![Yii2](https://camo.githubusercontent.com/3f29058a9886ae3e9efc09df82d551051f8ea6c8da1176d9e8ca8a64be6f9b40/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f72657175697265642d596969325f76322e302e34302d626c75652e737667)](https://packagist.org/packages/yiisoft/yii2)[![Downloads](https://camo.githubusercontent.com/d6cce284e2206827925274ee86df588f64fde689d1a95d66439aebd207954a63/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f77646d672f796969322d6170692e737667)](https://packagist.org/packages/wdmg/yii2-api)[![Packagist Version](https://camo.githubusercontent.com/ccf6a0705b83070f3646c1535e9d530677b69a8e535a1399a8ba119e9c91c31d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f77646d672f796969322d6170692e737667)](https://packagist.org/packages/wdmg/yii2-api)[![Progress](https://camo.githubusercontent.com/d2c102b075c16f8a841e697b04c43bc93c8d092c5795ad8b3090d7fa993c258a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70726f67726573732d72656164795f746f5f7573652d677265656e2e737667)](https://camo.githubusercontent.com/d2c102b075c16f8a841e697b04c43bc93c8d092c5795ad8b3090d7fa993c258a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70726f67726573732d72656164795f746f5f7573652d677265656e2e737667)[![GitHub license](https://camo.githubusercontent.com/53f8d43bc6f25727ee1580d611133d18e92b1dfe3d9cbec31843ff0c886f39c6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f77646d672f796969322d6170692e737667)](https://github.com/wdmg/yii2-api/blob/master/LICENSE)

[![Yii2 API module](./docs/images/yii2-api.png)](./docs/images/yii2-api.png)

Yii2 API
========

[](#yii2-api)

API control module for Yii2. This module is an integral part of the [Butterfly.СMS](https://butterflycms.com/) content management system, but can also be used as an standalone extension. Copyrights (c) 2019-2023 [W.D.M.Group, Ukraine](https://wdmg.com.ua/)

Requirements
============

[](#requirements)

- PHP 5.6 or higher
- Yii2 v.2.0.40 and newest
- [Yii2 Base](https://github.com/wdmg/yii2-base) module (required)
- [Yii2 Users](https://github.com/wdmg/yii2-users) module (required)
- [Yii2 Options](https://github.com/wdmg/yii2-options) module (support)
- [Yii2 SelectInput](https://github.com/wdmg/yii2-selectinput) widget
- [ClipboardJS](https://github.com/zenorocha/clipboard.js) asset library (required)

Installation
============

[](#installation)

To install the module, run the following command in the console:

`$ composer require "wdmg/yii2-api"`

After configure db connection, run the following command in the console:

`$ php yii api/init`

And select the operation you want to perform:

1. Apply all module migrations
2. Revert all module migrations

Migrations
==========

[](#migrations)

In any case, you can execute the migration and create the initial data, run the following command in the console:

`$ php yii migrate --migrationPath=@vendor/wdmg/yii2-api/migrations`

Configure
=========

[](#configure)

To add a module to the project, add the following data in your configuration file:

```
'modules' => [
    ...
    'api' => [
        'class' => 'wdmg\api\Module',
        'routePrefix' => 'admin', // routing prefix for dashboard
        'accessTokenExpire', => 3600 // lifetime of `access_token`, `0` - unlimited
        'blockedIp' => [], // array, blocked access from IP`s
        'rateLimit' => 30, // request`s to API per minute
        'rateLimitHeaders' => false, // send HTTP-headers of rate limit
        'sendAccessToken' => true, // send access token with HTTP-headers
        'authMethods' => [ // auth methods to allow
            'basicAuth' => true,
            'bearerAuth' => true,
            'paramAuth' => true
        ],
        'authMethods' => [ // allowed API modes
            'public' => true,
            'private' => true
        ],
        'allowedApiModels' => [ // allowed API models
            'public' => [
                "wdmg\api\models\api\NewsAPI" => true,
                "wdmg\api\models\api\OptionsAPI" => false,
                "wdmg\api\models\api\PagesAPI" => false,
                "wdmg\api\models\api\UsersAPI" => false,
                ...
            ],
            'private' => [
                "wdmg\api\models\api\NewsAPI" => true,
                "wdmg\api\models\api\OptionsAPI" => true,
                "wdmg\api\models\api\PagesAPI" => true,
                "wdmg\api\models\api\UsersAPI" => true,
                ...
            ],
        ]
    ],
    ...
],

```

Usecase
=======

[](#usecase)

Request to API with base auth by username and password (option `authMethods['basicAuth']` must be set to `true`):

```
$ curl 'http://example.com/api/users' \
-XGET \
-H 'Accept: application/json, text/javascript, */*; q=0.01' \
-H 'Authorization: Basic YOUR_USERNAME_AND_PASSWORD'

```

**Attention!** YOUR\_USERNAME\_AND\_PASSWORD in format `username:password` and has been encoded, like `base64_encode('username:password')`After successful authorization, the server will return `X-Access-Token` for use in other requests (option `sendAccessToken` must be set to `true`).

Request to API with query param `access_token` (option `authMethods['paramAuth']` must be set to `true`):

```
$ curl 'http://example.com/api/users?access-token=YOUR_API_ACCESS_TOKEN' \
-XGET \
-H 'Accept: application/json, text/javascript, */*; q=0.01'

```

Request to API with bearer `access_token` (option `authMethods['bearerAuth']` must be set to `true`):

```
$ curl 'http://example.com/api/users' \
-XGET \
-H 'Accept: application/json, text/javascript, */*; q=0.01' \
-H 'Authorization: Bearer YOUR_API_ACCESS_TOKEN'

```

If the access token has expired, the server will return new `X-Access-Token` for use in other requests (option `sendAccessToken` must be set to `true`).

Routing
=======

[](#routing)

Admin dashboard path by default:

Path for access to API endpoint: `model/module/action`Also see official guideline:

Use the `Module::dashboardNavItems()` method of the module to generate a navigation items list for NavBar, like this:

```

```

Status and version \[ready to use\]
===================================

[](#status-and-version-ready-to-use)

- v.2.0.1 - Add log activity, fix users API save/update
- v.2.0.0 - Basic Auth fixed
- v.1.4.0 - Update dependencies, copyrights
- v.1.3.12 - Added base API for Menu module, request helper
- v.1.3.11 - Update README.md and dependencies
- v.1.3.10 - Added base API for Comments module

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~41 days

Recently: every ~276 days

Total

37

Last Release

1054d ago

Major Versions

0.0.3 → 1.0.02019-05-27

1.4.0 → 2.0.02023-06-17

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1635637?v=4)[Alexsander Vyshnyvetskyy](/maintainers/alex-wdmg)[@alex-wdmg](https://github.com/alex-wdmg)

---

Top Contributors

[![alex-wdmg](https://avatars.githubusercontent.com/u/1635637?v=4)](https://github.com/alex-wdmg "alex-wdmg (83 commits)")

---

Tags

apiyii2wdmgyii2-api

### Embed Badge

![Health badge](/badges/wdmg-yii2-api/health.svg)

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

###  Alternatives

[dotzero/yii2-amocrm

Расширение для Yii Framework 2 реализующее клиент для работы с API amoCRM

1639.7k](/packages/dotzero-yii2-amocrm)[skeeks/yii2-google-api

Component for work with google api based on google/apiclient

1243.1k1](/packages/skeeks-yii2-google-api)

PHPackages © 2026

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