2017 © Pedro Peláez
 

library yii2-api

An auto-generated API

image

hdyusf/yii2-api

An auto-generated API

  • Saturday, April 28, 2018
  • by hdyusf
  • Repository
  • 0 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Home page

How to install?

composer require hdyusf/yii2-api

How to use?

  1. Install the library.
  2. Create a new module config to main-local.php like this: 'modules' => [ 'api' => [ 'class' => 'Hdyusf\yii2_api\Module', 'defaultRoute' => 'index', //默认控制器 'appControllers' => true, //是否检测app\controllers命名空间下的控制器 'suffix' => '', //api后缀 'prefix' => '', //api前缀 'modules' => [ //需要生成文档的模块命名空间 'frontend\controllers\UserController', ], ], ],
  3. Open the url from you browser. http://url.com?r=api

Example

The code like this:

/**
 * 这是一个测试的Api
 * @desc 列举所有的注释格式
 * @param string $user_type |用户类型|yes|其他说明|
 * @param int $sex |性别|no|0:不限 1:男 2:女|
 * @return int status 操作码,0表示成功
 * @return array list 用户列表
 * @return int list[].id 用户ID
 * @return string list[].name 用户名字
 * @return string msg 提示信息
 * @exception 400 参数传递错误
 * @exception 500 服务器内部错误
 */
public function actionDemoapi($user_type, $sex)
{
    $result = [
        'status' => 0,
        'list' => [
            'id' => 1,
            'name' => 'kaopur'
        ],
        'msg' => 'OK'
    ];
    return \yii\helpers\Json::encode($result);
}

Show

image, (*1)

The Versions

28/04 2018

dev-master

9999999-dev https://github.com/hdyusf/yii2-api

An auto-generated API

  Sources   Download

MIT

yii2-api