lidongyooo/laravel-idempotent
laravel idempotent
2,203
13
| Install | |
|---|---|
composer require lidongyooo/laravel-idempotent |
|
| Latest Version: | 1.0.1 |
| PHP: | >=7.0.0 |
| License: | MIT |
| Last Updated: | Jul 6, 2021 |
| Links: | GitHub · Packagist |
Maintainer: lidongyooo
Laravel-Idempotent
基于 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);
更多详细介绍请查看 配置文件
Related Packages
php-tmdb/laravel
Laravel Package for TMDB ( The Movie Database ) API. Provides easy access to the...
53,312
160