Skip to content

Commit

Permalink
Add information on withoutMiddleware and rate limit throttling (#197)
Browse files Browse the repository at this point in the history
Co-authored-by: Luke Towers <[email protected]>
  • Loading branch information
josephcrowell and LukeTowers authored Jul 8, 2024
1 parent 63e8add commit 8b95576
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion services/router.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,49 @@ Route::group(['middleware' => 'Path\To\Your\Middleware'], function() {
});
```

And finally, if you want to assign a group of middleware to just one route you can it like this
If you want to assign a group of middleware to just one route you can it like this

```php
Route::middleware(['Path\To\Your\Middleware'])->group(function() {
Route::get('info', 'Acme\News@info');
});
```

And finally, if you want to remove middleware from a route you can it like this

```php
Route::withoutMiddleware(\Path\To\Removed\Middleware::class)
->get('info', 'Acme\News@info');
```

You can of course add more than one middleware in a group, just one is used in the above examples for convenience.

## Throttle middleware

When using Winter's `api` middleware, you can remove the default rate limiting of 60 requests per minute and replace it with your own by using the below example:

```php
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;

RateLimiter::for("infoThrottle", function (Request $request) {
return Limit::perMinute(120);
});

Route::group(
[
"prefix" => "api",
"middleware" => ["api"],
],
function () {
Route::withoutMiddleware("throttle:60,1")
->middleware("throttle:infoThrottle")
->get('info', 'Acme\News@info');
}
);
```

## Throwing 404 errors

There are two ways to manually trigger a 404 error from a route. First, you may use the `abort` helper. The `abort` helper simply throws a `Symfony\Component\HttpFoundation\Exception\HttpException` with the specified status code:
Expand Down

0 comments on commit 8b95576

Please sign in to comment.