Laravel API Rate Limiting: Default and Custom Throttle

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys this week on this channel I'm showing random code Snippets from laral dailyom website from our own codebase and today I will talk about API rate limiting based on example of quick laral tips so maybe some of you don't know but on laral Daily website on top we have quick tips with a lot of tips around 500 and those are divided into topics and sections but what majority of you really don't know is we have public API for getting random tip so if you go to API V1 tips you would get something like this a Json with random tip if we refresh there will be another random tip we thought to use it ourselves to show the tips on other websites or Twitter or something like that but in the end we abandoned that idea but the API still stayed working but how could we protect that from being abused from spam and stuff like that although it is public as you can see I'm not logged in or anything it's not in po Postman with sanctum or anything like that so the URL is like this in routes API we have just tips with controller random method it doesn't that matter that much what is in controller what matters is this throttle random tips laral has a function of throttling API requests or in fact any request and you can Define your own rules for that so in route service provider there's configure rate limiting function and you may Define the default rules for API so per minute we have 60 attempts but specifically for random tips so we came up with our own name of that throttle rules we have it customized so if it's local then there's no limit but if it's from outside we limit 10 attempts so 10 API requests per minute and those are identified uniquely by user ID if they are logged in or if they are not logged in then 10 requests per minute by IP address so this is kind of a twoin one for you maybe some of you didn't know about rate limiter at all that it can be customized for apis and also some of you wouldn't know that you can create your own rate limiter like this with custom rules and then assign it to the route by providing the throttle random tips here as a middleware there's also a separate section in Lal documentation about rate limiting with caching so I will link that as well in the description below that's it for this time and see you guys in other videos
Info
Channel: Laravel Daily
Views: 6,538
Rating: undefined out of 5
Keywords:
Id: tNU9nZ7ZqBc
Channel Id: undefined
Length: 2min 28sec (148 seconds)
Published: Thu Oct 05 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.