YII2 's Fast Provisioning API Service YII2-FAST-API

Source: Internet
Author: User

Yii2-fast-api

Yii2-fast-api is an extension of the YII2 framework that is used to configure the YII2 to enable rapid development of APIs.

The default scenario for this extension is the development of the backend interface of the app, which is therefore biased towards pragmatism and does not fully adopt the RESTFULL standard to facilitate front-end development of processing interface data and various anomalies.

Installation installation with Composer
    • Add dependencies to the files in your project composer.json :
"Require": {    "DEEPZIYU/YII-FAST-API": "*"}
    • $ php composer.phar updateto perform or $ composer update install.

    • The FAST-API configuration is injected in the configuration file (Yii2 Premium for MAIN.PHP,YII2 basic version web.php):

$config for your original configuration $config = Yiihelpersarrayhelper::merge (    $config,    deepziyuyiirestcontroller::getconfig ()) ; return $config;
Usage
    • Building a Controllerclass YourController extends deepziyuyiirestController { /** * 示例接口 * @param int $id 请求参数 * @return string version api版本 * @return int yourId 你的请求参数 */ public function actionIndex($id) { return [‘version‘=>‘1.0.0‘,‘yourId‘=>$id]; } }
    • Send a request to see

Normal request

Post/your/index http/1.1host:yoursite.comcontent-type:application/json{"id": "10"}

Return

{    "code": $,    "data": {        "version": "1.0.0",        "Yourid": "Ten"    },    "message": "OK"}

Request with missing parameter

Post/your/index Http/1.1host:yoursite.comcontent-type:application/json

return error

{    "code": $,    "data": {},    "message": "Missing parameter: ID"}
    • View the automatically generated API documentation

http://yoursite.com/route/api/index

Words in the End

Thanks to the PHALAPI project at night in Mars, this YII2 extension provides design ideas.

Todo
    • More Complete Documentation Guide
    • Signature Filter Plug-in
    • Usage of current limit plug-in
    • Reference for RequestID and log storage tracking

This article goes from Code Cloud recommendation | YII2-based Fast Provisioning API Service YII2-FAST-API, only for learning and communication use!

YII2 's Fast Provisioning API Service YII2-FAST-API

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.