Created
September 24, 2018 13:29
-
-
Save azazqadir/77ba93bd273ed5908d64972e96b244b7 to your computer and use it in GitHub Desktop.
Laravel API Rate Limiting and Dynamic Rate Limiting: https://www.cloudways.com/blog/laravel-and-api-rate-limiting/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()], | |
200); | |
} | |
$task = new Task; | |
$task->names = $request->names; | |
$task->save(); | |
return response()->json(['response' => "Added {$request->names} to tasks."], | |
200); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment