Skip to content

Instantly share code, notes, and snippets.

@azazqadir
Created September 24, 2018 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azazqadir/77ba93bd273ed5908d64972e96b244b7 to your computer and use it in GitHub Desktop.
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/
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