Skip to content

Commit

Permalink
Add information on withoutMiddleware and rate limit throttling
Browse files Browse the repository at this point in the history
  • Loading branch information
josephcrowell committed Jul 8, 2024
1 parent 60e3219 commit cfcbab3
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion services/router.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,50 @@ 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")
->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 60 request per minute rate throttle applied to Winter's
API middleware and replace it with your own. For 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 cfcbab3

Please sign in to comment.