# yii2_restful_api_demo **Repository Path**: maoyunzhi/yii2_restful_api_demo ## Basic Information - **Project Name**: yii2_restful_api_demo - **Description**: 针对yii2提供的RESTful web服务,从最简单的,到各类配置都运用上的Demo - **Primary Language**: PHP - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2022-12-19 - **Last Updated**: 2023-02-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: Yii2-RESTful-API, yii2-api-demo ## README

Yii2.0 RESTfuel Web服务 Demo


Yii 2.0 Basic Template is a skeleton [Yii 2](http://www.yiiframework.com/) application best for rapidly creating small projects. The template contains the basic features including user login/logout and a contact page. It includes all commonly used configurations that would allow you to focus on adding new features to your application. DIRECTORY STRUCTURE ------------------- common/ contains common class config/ contains api configurations controllers/ contains api controller classes models/ contains model classes modules/ contains moduels files runtime/ contains files generated during runtime vendor/ contains dependent 3rd-party packages entrance/ contains the entry script REQUIREMENTS ------------ The minimum requirement by this project template that your Web server supports PHP 7.4.0. 下列接口统一需要在Header中添加
Accept: application/json RESTful Easy Api (极简接口) ------------------ 极简的API,仅用到VersionController extends \yii\rest\Controller ,但什么都没使用。
* /entrance/easy_api/version
帮助理解restful 使用到的配置文件,以及美化url。也可以从这里开始返回纯静态的模拟数据。
不用考虑认证、限速、版本等问题,可以直接开始编写业务逻辑,以及数据库操作。 RESTful Simple Api (简单接口) --------------------- 主要实现了Yii2默认带的认证方案,主要是http_bearer_auth 和 query_param_auth,针对一些演示性的接口,只需要有最简单的认证即可。 * 接口1: /entrance/simple_api/bearer-auth
在Header中添加
Authorization: Bearer 101-token * 接口2: /entrance/simple_api/query-auth?access-token=101-token * 接口3: /entrance/simple_api/api?access-token=101-token

/entrance/simple_api/api
在Header中添加
Authorization: Bearer 101-token RESTful Standard Api (标准接口) --------------------- 作为采用Yii2 的RESTful Web服务的API接口,把官方自带的一些基本功能都应用了。
包括版本管理,速率限制,两种认证模式,格式化响应,统一返回样式,错误处理。
需注意,使用默认的速率限制必须采用数据库模式,也就是必须对接数据库。数据库创建参考db.sql * 接口1: /entrance/standard_api/v1/api?access-token=cccddart12FDD