How To Set API Rate Limiting In Laravel

Submitted by azazqadir - 1 year ago

Rate limiting is the control of the number of requests per unit time. It can be applied to ports, IPs, routes, etc. when used correctly, it can efficiently block out malicious bots. In the case of our API, it can mitigate DOS attacks , thus, making our API accessible without downtime for legitimate users. Source:

Route::group(['prefix' => 'api/v1'], function () {
Route::get('/getTasks', function () {
return Task::all();
Route::post('/addTask', function (Request $request) {
$validator = Validator::make($request->all(), [
'names' => 'required|max:255',
if ($validator->fails()) {
return response()->json(['error' => $validator->messages()],
$task = new Task;
$task->names = $request->names;
return response()->json(['response' => "Added {$request->names} to tasks."],

Ads cover the costs of maintaining Laravel-tricks

comments powered by Disqus

Ads cover the costs of maintaining Laravel-tricks