Matt Stauffer continues his series looking at the improvements in Laravel 5.2 with this new post talking about the included rate limiting functionality.
More and more of my work in Laravel lately has been creating APIs. I have a manual rate limiter class I've been using, but I've had a sense that there's a cleaner way to do it. Unsurprisingly, when Taylor set out to write a rate limiter middleware for Laravel, he did it cleaner and better than I had.
Matt briefly introduces the concept of rate limiting and how some optional headers (in the X-
family) can be used to let the end user/script know when their requests will be rate limited: X-RateLimit-Limit
, X-RateLimit-Remaining
and Retry-After
. He then gets into the example of it in use, showing how to simply add the middleware to the routing and the results in the HTTP response. He ends the post with a bit on customizing the middleware, updating both the times per minute setting and a "block" time limit for when to completely block out the user.