PHPackages                             myzero1/yii2-rest - 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. myzero1/yii2-rest

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

myzero1/yii2-rest
=================

Ti is for restful api by yii2.

1.0.2(7y ago)015MITPHP

Since Mar 5Pushed 7y agoCompare

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

READMEChangelog (2)Dependencies (3)Versions (6)Used By (0)

yii2-rest
=========

[](#yii2-rest)

Rest api with wagger in yii2.

Show time
---------

[](#show-time)

[![](https://github.com/myzero1/show-time/raw/master/yii2-rest/screenshot/201.png)](https://github.com/myzero1/show-time/blob/master/yii2-rest/screenshot/201.png)[![](https://github.com/myzero1/show-time/raw/master/yii2-rest/screenshot/202.png)](https://github.com/myzero1/show-time/blob/master/yii2-rest/screenshot/202.png)[![](https://github.com/myzero1/show-time/raw/master/yii2-rest/screenshot/203.png)](https://github.com/myzero1/show-time/blob/master/yii2-rest/screenshot/203.png)[![](https://github.com/myzero1/show-time/raw/master/yii2-rest/screenshot/204.png)](https://github.com/myzero1/show-time/blob/master/yii2-rest/screenshot/204.png)[![](https://github.com/myzero1/show-time/raw/master/yii2-rest/screenshot/205.png)](https://github.com/myzero1/show-time/blob/master/yii2-rest/screenshot/205.png)[![](https://github.com/myzero1/show-time/raw/master/yii2-rest/screenshot/206.png)](https://github.com/myzero1/show-time/blob/master/yii2-rest/screenshot/206.png)[![](https://github.com/myzero1/show-time/raw/master/yii2-rest/screenshot/207.png)](https://github.com/myzero1/show-time/blob/master/yii2-rest/screenshot/207.png)

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

[](#installation)

The preferred way to install this module is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require myzero1/yii2-rest：1.*

```

or add

```
"myzero1/yii2-rest": "~1"

```

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

Setting
-------

[](#setting)

Once the extension is installed, simply modify your application configuration(main.php) as follows:

```
return [
    ......
    'bootstrap' => [
        ......
        'log',
        [
            'class' => 'backend\modules\v1\Bootstrap',
            'params' => [
                'apiTokenExpire' => 1*24*3600,
                'rateLimit' => [2000,3], // 2times/3s
                'swaggerConfig' => [
                    'schemes' => '{http}',
                    'host' => 'yii2rest3.test',
                    'basePath' => '/v1',
                    'info' => [
                        'title' => '接口文档',
                        'version' => '1.0.0',
                        'description' => '这是关于: __react-admin__（https://github.com/marmelab/react-admin/tree/master/packages/ra-data-simple-rest）的rest api',
                            'contact' => [
                                'name' => 'myzero1',
                                'email' => 'myzero1@sina.com',
                            ],
                    ]
                ],
            ],
        ],
        ......
    ],
    ......
    'components' => [
        ......
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [],
        ],
        ......
    ],
    ......
];
```

Setting the gii in main-local.php as follows:

```
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        'allowedIPs' => ['*'],
        'generators' => [
            'module-rest-swagger' => [
                'class' => 'myzero1\rest\gii\auth\Generator',
                'templates' => [
                    'rest' => 'myzero1\rest\gii\auth\default'
                ]
            ],
            'obj-rest-swagger' => [
                'class' => 'myzero1\rest\gii\object\Generator',
                'templates' => [
                    'rest' => 'myzero1\rest\gii\object\default'
                ]
            ],
        ]
    ];
```

Setting the actions in siteController.php as follows:

```
use yii\filters\AccessControl;
use yii\helpers\Url;
......
    /**
     * {@inheritdoc}
     */
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'rules' => [
                    [
                        'actions' => ['login', 'error'],
                        'allow' => true,
                    ],
                    [
                        'actions' => ['logout', 'index', 'doc', 'api'],
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'logout' => ['post'],
                ],
            ],
        ];
    }
......
    /**
     * {@inheritdoc}
     */
    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
            ],
            'doc' => [
                'class' => 'myzero1\rest\swaggertools\SwaggerAction',
                'restUrl' => url::to(['/site/api'], true),
            ],
            'api' => [
                'class' => 'myzero1\rest\swaggertools\SwaggerApiAction',
                'scanDir' => [
                    Yii::getAlias('@vendor/myzero1/yii2-rest/src/swaggertools/config'),
                    Yii::getAlias('@backend/modules/v1/swagger'),
                ],
                // 'api_key' => 'test'
            ],
        ];
    }
```

Usage
-----

[](#usage)

You can then access swagger page.

```
http://yii2rest2.test/site/doc

```

You can then access gii page to watch the rest generator.

```
http://yii2rest2.test/gii/default/view?id=api-rest

```

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity64

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

Total

2

Last Release

2672d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/22048203?v=4)[myzero1](/maintainers/myzero1)[@myzero1](https://github.com/myzero1)

---

Top Contributors

[![myzero1](https://avatars.githubusercontent.com/u/22048203?v=4)](https://github.com/myzero1 "myzero1 (77 commits)")

### Embed Badge

![Health badge](/badges/myzero1-yii2-rest/health.svg)

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

###  Alternatives

[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

2.9k36.4M127](/packages/darkaonline-l5-swagger)[light/yii2-swagger

swagger intergation with yii2

153835.2k4](/packages/light-yii2-swagger)[yii2mod/yii2-swagger

Swagger Documentation Generator for Yii2 Framework

63398.2k9](/packages/yii2mod-yii2-swagger)[litalico-engineering/eg-r2

Easy request validation and route generation from open API specifications (for Laravel)

1114.6k](/packages/litalico-engineering-eg-r2)[ignatenkovnikita/yii2-swagger

Swagger UI v3 intergation with yii2

128.1k](/packages/ignatenkovnikita-yii2-swagger)

PHPackages © 2026

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