我正在编写大量API来获取和存储数据.
我喜欢默认throttle选项:
protected $middlewareGroups = [
'api' => [
'throttle:60,1',
'bindings',
],
];
Run Code Online (Sandbox Code Playgroud)
将请求限制在每分钟60个; 但是对于某些路线(es :) POST,我想增加这个值.
我尝试设置'throttle:500,1'路由中间件,如下所示:
Route::group(function () {
Route::get('semaphore/1', ['uses' => 'App\Api\V1\DBs\SemaphoreController@index']);
Route::post('semaphore/1', ['uses' => 'App\Api\V1\DBs\SemaphoreController@store', 'middleware' => 'WriteToDatabaseMiddleware', 'throttle:500,1']);
});
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
任何的想法?
谢谢.
更新:
我注意到路由中'throttle:500,1'使用的api.php将在默认'throttle:60,1'指定的Kernel.php文件后设置; 那么,它不起作用.
记录流程执行,第一个调用是:
Illuminate\Routing\Middleware\ThrottleRequests -> handle
Run Code Online (Sandbox Code Playgroud)
从Kernel.php有maxAttempts=60.
然后,第二个电话是:
Illuminate\Routing\Middleware\ThrottleRequests -> handle
Run Code Online (Sandbox Code Playgroud)
从api.php有maxAttempts=500.
在其他也就是说,throttle:500,1中api.php文件没有覆盖throttle:60,1的的Kernel.php文件.
使用该方法updateOrCreate,有没有办法知道记录是更新或创建的?
更新:
我需要使用此功能返回201,创建记录或204更新记录.
谢谢.
我正在构建一个简单的 OpenAPI 3 YAML 规范,如下所示:
paths:
/query:
get:
parameters:
- $ref: '#/components/parameters/bookid'
components:
parameters:
bookid:
in: query
name: bookid
required: false
schema:
format: integer
type: number
Run Code Online (Sandbox Code Playgroud)
现在,我想使用通用bookid 参数,但覆盖to 的required值。例如(这不起作用!!!):falsetrue
paths:
...
/query2:
get:
parameters:
- $ref: '#/components/parameters/bookid'
required: true # <--- ???
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?
我正在使用 Laravel 8 构建一个带有分页 JSON 的简单 API。
输出包含一个“链接”对象到“元”键:
{
"data": [
{
. . .
},
{
. . .
}
],
"links": {
"prev": null,
"first": "http://localhost/api/my-api?&page=1",
"next": null,
"last": "http://localhost/api/my-api?&page=2"
},
"meta": {
"from": 1,
"per_page": 400,
"total": 477,
"current_page": 1,
"last_page": 2,
"path": "http://localhost/api/my-api",
"to": 400,
"links": [
{
"url": null,
"label": "Previous",
"active": false
},
{
"url": "http://localhost/api/my-api?&page=1",
"label": 1,
"active": true
},
{
"url": "http://localhost/api/my-api?&page=2",
"label": 2,
"active": false
},
{
"url": "http://localhost/api/my-api?&page=2",
"label": "Next", …Run Code Online (Sandbox Code Playgroud) 我正在测试“并发请求”功能:
但我对如何动态创建闭包输入值感到困惑。
例如我有一个数组:
$a = [
'foo' => 'http//localhost/1',
'bar' => 'http//localhost/2'
];
Run Code Online (Sandbox Code Playgroud)
我需要动态地创建类似的东西:
use Illuminate\Http\Client\Pool;
use Illuminate\Support\Facades\Http;
$responses = Http::pool(fn (Pool $pool) => [
$pool->as('foo')->get('http://localhost/1'),
$pool->as('bar')->get('http://localhost/2'),
]);
return $responses['foo']->body();
Run Code Online (Sandbox Code Playgroud)
更新$a关闭内容应该发生变化。我怎样才能做到这一点?
谢谢
php ×3
laravel-5.4 ×2
laravel-8 ×2
api ×1
closures ×1
eloquent ×1
http ×1
openapi ×1
pagination ×1
request ×1
throttling ×1