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 update
to 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 Controller
class 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