How to use API Routes in Laravel 5.3 How to use API Routes in Laravel 5.3 laravel laravel

How to use API Routes in Laravel 5.3


You call it by

http://localhost:8080/api/test                      ^^^

If you look in app/Providers/RouteServiceProvider.php you'd see that by default it sets the api prefix for API routes, which you can change of course if you want to.

protected function mapApiRoutes(){    Route::group([        'middleware' => 'api',        'namespace' => $this->namespace,        'prefix' => 'api',    ], function ($router) {        require base_path('routes/api.php');    });}


If you want to customize this or add your own separate routes files, check out App\Providers\RouteServiceProvider for inspiration

https://mattstauffer.co/blog/routing-changes-in-laravel-5-3


routes/api.php

Route::get('/test', function () {    return response('Test API', 200)                  ->header('Content-Type', 'application/json');});

Mapping is defined in service provider App\Providers\RouteServiceProvider

protected function mapApiRoutes(){    Route::group([        'middleware' => ['api', 'auth:api'],        'namespace' => $this->namespace,        'prefix' => 'api',    ], function ($router) {        require base_path('routes/api.php');    });}