sstringer's avatar

How to Use ThrottleRequests in Lumen 5.2?

I'd like to use Laravel 5.2's ThrottleRequests middleware in Lumen. Unless I'm missing something, it does not appear that Lumen provides any throttling which seems backwards, imho, since Lumen's Special Purpose is to enable the development of APIs which need throttling.

  1. Sanity check: am I missing something? Does Lumen 5.2 have throttling and I'm just dense?

  2. Assuming not, is there a way to easily install the Illuminate ThrottleRequests class as middleware in Lumen?

  3. Is there a third-party alternative that provides elegant and lightweight throttling? Or am I better off waiting for ThrottleRequests to appear in Lumen 5.3?

Many thanks, Steve

0 likes
4 replies
inad9300's avatar

I tried this approach, but it didn't work; I receive the error Fatal error: Call to a member function methods() on array.

This happens when the Illuminate\Http\Request::fingerprint() method is called, which contains this call: $this->route()->methods(). In turn, that route() method is supposed to return an Illuminate\Routing\Route object , which is not happening in Lumen (I guess it does happen in Laravel).

So I wasn't able to add rate limiting capabilities to Lumen through their own facilities... And I think it should be even more prepared than Laravel for that, considering its API-only focus. I guess the only option here is to try to look into another approaches, like Laravel-Throttle or Dingo API. But it would be really nice to hear about throttling coming natively to Lumen.

Please or to participate in this conversation.