Difference between web and api routes in Laravel

Morris Muriuki Muthigani

05/16/2023 (1 year ago)

After creating a brand new Laravel (I'm using v9) project you'll find multiple files in the routes directory.

laravel-project $ tree routes/
├── api.php
├── channels.php
├── console.php
└── web.php

The channels.php file is for broadcasting and console.php for command closures. The other two, api.php and web.php, are pretty similar and both for web routes. But how are they different? For this we need to reach for the RouteServiceProvider (see below).

In the boot() method of the RouteServiceProvider we see that both the api and web routes are registered. They are registered with a couple differences though.

As you can see below there are three notable differences:

  • There is rate limiting configured for api routes.
  • Api routes use the api middleware group where web routes use the web middleware group.
  • Api have the api prefix, thus routes from the api.php are prefixed with api/.

The different middleware groups can be found in app/Http/Kernel.php.


// ...

class RouteServiceProvider extends ServiceProvider
    // ..

     * Define your route model bindings, pattern filters, and other route configuration.
     * @return void
    public function boot()

        $this->routes(function () {


     * Configure the rate limiters for the application.
     * @return void
    protected function configureRateLimiting()
        RateLimiter::for('api', function (Request $request) {
            return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());

Discussion (0)

Recent Blogs

Our Recent Blogs