2017 © Pedro Peláez
 

library yii2-fast-api

A component to develop api faster on yii2 framework

image

myzero1/yii2-fast-api

A component to develop api faster on yii2 framework

  • Monday, November 20, 2017
  • by myzero1
  • Repository
  • 0 Watchers
  • 0 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 8 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

yii2-fast-api

yii2-fast-api是一个Yii2框架的扩展,用于配置完善Yii2,以实现api的快速开发。 此扩展默认的场景是APP的后端接口开发,因此偏向于实用主义,并未完全采用restfull的标准,方便前端开发处理接口数据以及各种异常。, (*1)

Installation

使用 Composer 安装

  • 在项目中的 composer.json 文件中添加依赖:
"require": {
    "deepziyu/yii-fast-api": "*"
}
  • 执行 $ php composer.phar update$ composer update 进行安装。, (*2)

  • 在配置文件中( Yii2 高级版为 main.php,Yii2 基础版为 web.php )注入 fast-api 的配置:, (*3)

// $config 为你原本的配置
$config = yii\helpers\ArrayHelper::merge(
    $config,
    \deepziyu\yii\rest\Controller::getConfig()
);

return $config;

Usage

  • 建立控制器
class YourController extends deepziyu\yii\rest\Controller
{
    /**
     * 示例接口
     * @param int $id 请求参数
     * @return string version api版本
     * @return int yourId 你的请求参数
     */
    public function actionIndex($id)
    {
        return ['version'=>'1.0.0','yourId'=>$id];
    }
}
  • 发送请求看看

正常请求, (*4)

POST /your/index HTTP/1.1
Host: yoursite.com
Content-Type: application/json

{"id":"10"}

返回, (*5)

{
    "code": 200,
    "data": {
        "version": "1.0.0",
        "yourId": "10"
    },
    "message": "OK"
}

缺少参数的请求, (*6)

POST /your/index HTTP/1.1
Host: yoursite.com
Content-Type: application/json

返回错误, (*7)

{
    "code": 400,
    "data": {},
    "message": "缺少参数:id"
}
  • 查看自动生成的Api文档

http ://yoursite.com/route/api/index, (*8)

mahua, (*9)

Words In The End

感谢@暗夜在火星 的PhalApi项目,为此Yii2扩展提供设计的思路。, (*10)

TODO

  • 更完善的文档指南
  • Signature 过滤器插件
  • 限流插件的使用
  • RequestID 以及日志存储追踪的参考

The Versions

20/11 2017

dev-master

9999999-dev

A component to develop api faster on yii2 framework

  Sources   Download

BSD-3-Clause

The Requires

 

by Avatar deepziyu

20/11 2017

1.0.0

1.0.0.0

A component to develop api faster on yii2 framework

  Sources   Download

BSD-3-Clause

The Requires

 

by Avatar deepziyu