lidongyooo/laravel-idempotent
最新稳定版本:1.0.1
Composer 安装命令:
composer require lidongyooo/laravel-idempotent
包简介
laravel idempotent
关键字:
README 文档
README
基于 Laravel 的接口幂等组件
安装
$ composer require lidongyooo/laravel-idempotent -vvv
配置
- 在
config/app.php注册 ServiceProvider (Laravel 5.5 + 无需手动注册)
'providers' => [ // ... Lidongyooo\Idempotent\IdempotentServiceProvider::class, ],
- 创建配置文件
$ php artisan vendor:publish --tag="laravel-idempotent"
- 查看应用根目录下的
config/idempotent.php
使用
中间件 Lidongyooo\Idempotent\IdempotentMiddleware,别名 idempotent
// ... Route::post('/test', function () { return 'test'; })->middleware('idempotent'); //如果你想强制缓存响应 Route::post('/test', function () { return 'test'; })->middleware('idempotent:true');
或者你可以将它加入到指定路由中间件组中
protected $middlewareGroups = [ // ... 'api' => [ 'idempotent', 'throttle:api', \Illuminate\Routing\Middleware\SubstituteBindings::class, ], ];
返回值
- 重复请求将会返回异常
abort(425, 'Your request is still being processed.');
- 已缓存的请求将添加响应头
$response->header($this->config['back_header_name'], $idempotentKey);
更多详细介绍请查看 配置文件
统计信息
- 总下载量: 2.15k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-06-26