1

I have a group of endpoints that I want to have a throttle of 10 requests per minute. Currently, my endpoint group looks like this:

Route::group([
    'middleware' => 'auth:api', 'throttle:10,1'
], function () {
// endpoints here
}

The issue is that when I view my headers, the rate limit is set at the standard 60 per minute. What am I doing wrong? Or do you know a different way?

The response data is as follows:

cache-control: no-cache, private
content-encoding: gzip
content-type: application/json
date: Tue, 01 May 2018 20:08:55 GMT
server: nginx/1.14.0 (Ubuntu)
status: 200
vary: Accept-Encoding
x-ratelimit-limit: 60
x-ratelimit-remaining: 59

I tried the following:

Route::group([
    'middleware' => ['auth:api', 'throttle:10,1']
], function () {
// rest of code

But got the same result. So then I tried:

Route::group([
    'middleware' => 'throttle:10,1', 'auth:api'
], function () {
// rest of code

However, this gave me a 500 error. This told me that the middleware definitely had to be an array. However, when it is an array, it doesn't set the throttle to what I want it to be.

TytonDon
  • 563
  • 1
  • 5
  • 18
  • What do the headers say? – tadman May 01 '18 at 20:04
  • cache-control: no-cache, private content-encoding: gzip content-type: application/json date: Tue, 01 May 2018 20:08:55 GMT server: nginx/1.14.0 (Ubuntu) status: 200 vary: Accept-Encoding x-ratelimit-limit: 60 x-ratelimit-remaining: 59 – TytonDon May 01 '18 at 20:09
  • Since that's a lot of text that'd benefit from better formatting, edit your question to include that. In a comment it's just a jumble. – tadman May 01 '18 at 20:10
  • 1
    Done! :) Thanks. – TytonDon May 01 '18 at 20:11

2 Answers2

1

I have no way to test this, but I suspect you want:

Route::group([
    'middleware' => ['auth:api', 'throttle:10,1']
], function () {
// rest of code

(docs source)

That is, without putting 'auth:api' and 'throttle:10,1' into one array Laravel has no way to understand that the latter is also middleware.

Aurel Bílý
  • 7,068
  • 1
  • 21
  • 34
  • I have updated my question in response to this. Thank you for the heads up. Any help is appreciated. – TytonDon May 01 '18 at 20:23
0

I went into my Kernel.php file and added a new middleware group with the throttle I was wanting and removed the standard api one. This worked. I will have to create a new middleware group for each new one I make as well. I do not think it was supposed to be like this, but it is for now. Thank you for your help guys!

TytonDon
  • 563
  • 1
  • 5
  • 18