3

I read many post regarding new concept about api routing. I understood that api routing is used for mobile platforms but is there code level difference between them

In RouteServiceProvider i can see

/**
     * Define the "web" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     *
     * @return void
     */
    protected function mapWebRoutes()
    {
        Route::group([
            'middleware' => 'web',
            'namespace' => $this->namespace,
        ], function ($router) {
            require base_path('routes/web.php');
        });
    }

    /**
     * Define the "api" routes for the application.
     *
     * These routes are typically stateless.
     *
     * @return void
     */
    protected function mapApiRoutes()
    {
        Route::group([
            'middleware' => 'api',
            'namespace' => $this->namespace,
            'prefix' => 'api',
        ], function ($router) {
            require base_path('routes/api.php');
        });
    }

As per this web route uses

These routes all receive session state, CSRF protection, etc.

api route

These routes are typically stateless.

My question is

  1. What does it mean stateless in api route ?

  2. Web routing uses session state, CSRF protection. Does it mean api routing is not using session state, CSRF protection ?

  3. Laravel 5.3 uses seperate web and api routing, is there any advantages ?

ad3bay0
  • 125
  • 1
  • 8
iCoders
  • 6,929
  • 5
  • 34
  • 54

1 Answers1

12
  1. What does it mean stateless in api route ?

It means server doesn't save client 'state' between requests. Here is couple words about REST What exactly is RESTful programming?

  1. Web routing uses session state, CSRF protection. Does it mean api routing is not using session state, CSRF protection ?

All is possible but not required. You still can using sessions etc, but this is a REST principles violation.

  1. Laravel 5.3 uses seperate web and api routing, is there any advantages

It's just for your convenience. In Laravel 5.2 you need specify middleware for routes like ['web'] or ['api'] but it doesn't required anymore. In 5.3 routes stored in separated files and specify routes middleware not required.

ad3bay0
  • 125
  • 1
  • 8
aleksejjj
  • 1,655
  • 7
  • 20