承接 lidongyooo/laravel-idempotent 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lidongyooo/laravel-idempotent

最新稳定版本:1.0.1

Composer 安装命令:

composer require lidongyooo/laravel-idempotent

包简介

laravel idempotent

README 文档

README

基于 Laravel 的接口幂等组件

安装

$ composer require lidongyooo/laravel-idempotent -vvv

配置

  1. config/app.php 注册 ServiceProvider (Laravel 5.5 + 无需手动注册)
'providers' => [
    // ...
    Lidongyooo\Idempotent\IdempotentServiceProvider::class,
],
  1. 创建配置文件
$ php artisan vendor:publish --tag="laravel-idempotent"
  1. 查看应用根目录下的 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

GitHub 信息

  • Stars: 13
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-06-26