Last active
August 29, 2015 14:05
-
-
Save jasonlewis/1ca64d51d9c035098db0 to your computer and use it in GitHub Desktop.
Looking at an improved way of throttling API requests with the package. This will allow you to register custom throttles when you want to grant more requests for different types of authentication or user levels.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return [ | |
'throttling' => [ | |
new Dingo\Api\Http\RateLimit\AuthenticatedThrottle(['limit' => 0, 'expires' => 60]), | |
new Dingo\Api\Http\RateLimit\UnauthenticatedThrottle(['limit' => 0, 'expires' => 60]), | |
// Register a custom throttle. | |
new OAuth2Throttle(['limit' => 2000, 'expires' => 20]) | |
] | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class OAuth2Throttle extends Dingo\Api\Http\RateLimit\Throttle | |
{ | |
public function condition($app) | |
{ | |
return $app['api.auth']->via('oauth2'); | |
} | |
} |
I'd rather instantiate classes than use more multidimensional arrays
Yeah I'm much the same.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instead of instantiating the classes directly it might be better to instead use a multi-dimensional array?
I kind of like the cleanliness of instantiating the classes though.