Dingo\Api\Http\Middleware\RateLimit::handle PHP Method

handle() public method

Perform rate limiting before a request is executed.
public handle ( Dingo\Api\Http\Request $request, Closure $next ) : mixed
$request Dingo\Api\Http\Request
$next Closure
return mixed
    public function handle($request, Closure $next)
    {
        if ($request instanceof InternalRequest) {
            return $next($request);
        }
        $route = $this->router->getCurrentRoute();
        if ($route->hasThrottle()) {
            $this->handler->setThrottle($route->getThrottle());
        }
        $this->handler->rateLimitRequest($request, $route->getRateLimit(), $route->getRateLimitExpiration());
        if ($this->handler->exceededRateLimit()) {
            throw new RateLimitExceededException('You have exceeded your rate limit.', null, $this->getHeaders());
        }
        $response = $next($request);
        if ($this->handler->requestWasRateLimited()) {
            return $this->responseWithHeaders($response);
        }
        return $response;
    }