侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

单独讲一下laravel跟Dingo结合编写api及api路由配置文件的作用

Laravel  /  管理员 发布于 2年前   1130

单独讲一下这个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.png

1.默认每分钟600次

2.png

2.设置成每分钟400次

image.png


  • 上一条:
    根据不同的数字用php编程画出动态饼状图
    下一条:
    很久以前刚学php编程的时候写的单例模式理解逻辑分享一下
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在Laravel项目中使用中间件方式统计用户在线时长功能代码示例(0个评论)
    • 在Laravel中构建业务流程模型(0个评论)
    • 在Laravel项目中的实现无密码认证之:发送邮箱链接授权(0个评论)
    • Laravel 10.4版本发布(0个评论)
    • 在laravel框架中的5个HTTP客户端技巧分享(0个评论)
    • 近期文章
    • 如何优雅处理async await错误推荐:await-to-js库(0个评论)
    • lodash工具库(0个评论)
    • 在Laravel项目中使用中间件方式统计用户在线时长功能代码示例(0个评论)
    • 在Laravel中构建业务流程模型(0个评论)
    • windows系统中安装FFMpeg及在phpstudy环境php7.3 + php-ffmpeg扩展的使用流程步骤(0个评论)
    • 在go语言中对浮点的数组、切片(slice)进行正向排序和反向排序(0个评论)
    • 在go语言中对整数数组、切片(slice)进行排序和反向排序(0个评论)
    • 在go语言中对字符串数组、切片(slice)进行排序和反向排序(0个评论)
    • 最新国内免注册ChatGPT体验站_ChatGPT镜像站访问链接地址2023/3/28持续更新(0个评论)
    • 在Laravel项目中的实现无密码认证之:发送邮箱链接授权(0个评论)
    • 近期评论
    • 博主 在

      2023年国务院办公厅春节放假通知:1月21日起休7天中评论 @ xiaoB 你只管努力,剩下的叫给天意;天若有情天亦老,..
    • xiaoB 在

      2023年国务院办公厅春节放假通知:1月21日起休7天中评论 会不会春节放假后又阳一次?..
    • BUG4 在

      你翻墙过吗?国内使用vpn翻墙可能会被网警抓,你需了解的事中评论 不是吧?..
    • 博主 在

      go语言+beego框架中获取get,post请求的所有参数中评论 @ t1  直接在router.go文件中配就ok..
    • Jade 在

      如何在MySQL查询中获得当月记录中评论 Dear zongscan.com team, We can skyroc..
    • 2016-10
    • 2016-11
    • 2017-07
    • 2017-08
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2020-07
    • 2020-08
    • 2020-09
    • 2020-10
    • 2020-11
    • 2021-01
    • 2021-02
    • 2021-03
    • 2021-04
    • 2021-05
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-02
    • 2022-03
    • 2022-04
    • 2022-05
    • 2022-06
    • 2022-07
    • 2022-08
    • 2022-09
    • 2022-10
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客