单独讲一下laravel跟Dingo结合编写api及api路由配置文件的作用
Laravel  /  管理员 发布于 4年前   1596
单独讲一下这个api配置文件(我的接口路由都写这里):
\vendor\wanglelecc\laracms-framework\routes\api.php
截取一些常用的配置项及其作用 做注释
$api = app('Dingo\Api\Routing\Router');
/** v1 Version API Routes */
$api->version('v1', [
//命名空间 定义我的api的控制器
'namespace' => 'Wanglelecc\Laracms\Http\Controllers\Api\V1',
'middleware' => 'serializer:array',
], function($api) {
//api分组编写 字面意思相同的写到一起 方面维护管理及控制
$api->group([
//中间件
'middleware' => 'api.throttle',
//接口频率限制 次数
'limit' => config('api.rate_limits.sign.limit'),
//接口频率限制 时间(这里是时间 分钟)
'expires' => config('api.rate_limits.sign.expires'),
], function($api){
#里面就是接口路由了
$api->post('verificationCodes', 'VerificationCodesController@store')->name('api.verificationCodes.store');# 短信验证码
$api->post('users', 'UsersController@store')->name('api.users.store');# 用户注册
$api->post('captchas', 'CaptchasController@store')->name('api.captchas.store'); # 图片验证码
$api->post('socials/{social_type}/authorizations', 'AuthorizationsController@socialStore')->name('api.socials.authorizations.store');# 第三方登录
$api->post('authorizations', 'AuthorizationsController@store')->name('api.authorizations.store');# 登录
$api->put('authorizations/current', 'AuthorizationsController@update')->name('api.authorizations.update');# 刷新token
$api->delete('authorizations/current', 'AuthorizationsController@destroy')->name('api.authorizations.destroy');# 删除token
$api->get('cardnewsarticles/{category_id}', 'CardNewsArticleController@index')->name('api.article.index');
$api->get('cardnewssearcharticles', 'CardNewsArticleController@search');
$api->get('loansnewsarticles/{category_id}', 'CardNewsArticleController@loansart')->name('api.article.loansart');
$api->get('loansnewssearcharticles', 'CardNewsArticleController@loanssearch');
# 获取区块内容
$api->get('blocks/{block_id}', 'BlockController@show')->name('api.block.show');
//评论
$api->post('comment', 'CommentController@comment')->name('api.comment.comment');
$api->get('commentpages', 'CommentController@commentpages')->name('api.comment.commentpages');
//up/dowm
$api->get('creditcardupdown', 'CommentController@creditcardupdown')->name('api.comment.creditcardupdown');
});
//第二个api分组了 可以对应不同的接口频率限制 access
$api->group([
'middleware' => 'api.throttle',
'limit' => config('api.rate_limits.access.limit'),
'expires' => config('api.rate_limits.access.expires'),], function($api) {
//AB版
$api->get('cbbab', 'DbgController@ab')->name('api.dbg.ab');
//小程序
$api->get('xcxkfstatus', 'XcxController@xcxkfstatus')->name('api.xcx.xcxkfstatus');
$api->get('topcarousel', 'XcxController@topcarousel')->name('api.xcx.topcarousel');
$api->get('centericon', 'XcxController@centericon')->name('api.xcx.centericon');
$api->get('xcxcentericonid', 'XcxController@xcxcentericonid')->name('api.xcx.xcxcentericonid');
$api->get('xcxkfxx', 'XcxController@xcxkfxx')->name('api.xcx.xcxkfxx');
$api->post('xcxkfxx', 'XcxController@xcxkfxx')->name('api.xcx.xcxkfxx');
//baidu
$api->get('bxcxkfxx', 'XcxController@bxcxkfxx')->name('api.xcx.bxcxkfxx');
$api->post('bxcxkfxx', 'XcxController@bxcxkfxx')->name('api.xcx.bxcxkfxx');
});
});
接口频率限制 (上面的分组接口频率限制 时间次数就是读这里)
配置文件路径:\config\api.php
/** 接口频率限制 */
'rate_limits' => [
// 访问频率限制,次数/分钟
'access' => [
'expires' => env('RATE_LIMITS_EXPIRES', 1),
'limit' => env('RATE_LIMITS', 600),
],
// 登录相关,次数/分钟
'sign' => [
'expires' => env('SIGN_RATE_LIMITS_EXPIRES', 1),
'limit' => env('SIGN_RATE_LIMITS', 10),
],
],
看到没有两个分组读的是 assess跟sign
assess:config('api.rate_limits.access.limit')
sign:config('api.rate_limits.sign.limit')
看一下效果:
1.默认每分钟600次
2.设置成每分钟400次
123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..路人 在
php中使用hyperf框架调用讯飞星火大模型实现国内版chatgpt功能示例中评论 教程很详细,如果加个前端chatgpt对话页面就完美了..Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号