Api: error: "The version given was unknown or has no registered routes" with laravel 5.4

Created on 5 May 2017  路  5Comments  路  Source: dingo/api

While typing the uri 'my_domain.com/v1/home' in the browser, i got the error with the details as below:

  1. error:
{"message":"The version given was unknown or has no registered routes.","status_code":400,"debug":{"line":72,"file":"\/home\/vagrant\/Code\/yuanzihe\/vendor\/dingo\/api\/src\/Routing\/Adapter\/Laravel.php","class":"Dingo\\Api\\Exception\\UnknownVersionException","trace":["#0 \/home\/vagrant\/Code\/yuanzihe\/vendor\/dingo\/api\/src\/Routing\/Router.php(513): Dingo\\Api\\Routing\\Adapter\\Laravel->dispatch(Object(Dingo\\Api\\Http\\Request), 'v1')","#1 \/home\/vagrant\/Code\/yuanzihe\/vendor\/dingo\/api\/src\/Http\/Middleware\/Request.php(126): Dingo\\Api\\Routing\\Router->dispatch(Object(Dingo\\Api\\Http\\Request))","#2 \/home\/vagrant\/Code\/yuanzihe\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(114): Dingo\\Api\\Http\\Middleware\\Request->Dingo\\Api\\Http\\Middleware\\{closure}(Object(Dingo\\Api\\Http\\Request))","#3 \/home\/vagrant\/Code\/yuanzihe\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Http\/Middleware\/TransformsRequest.php(30): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))","#4 \/home\/vagrant\/Code\/yuanzihe\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(148): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))","#5 \/home\/vagrant\/Code\/yuanzihe\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Http\/Middleware\/TransformsRequest.php(30): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))","#6 \/home\/vagrant\/Code\/yuanzihe\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(148): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))","#7 \/home\/vagrant\/Code\/yuanzihe\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Http\/Middleware\/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))","#8 \/home\/vagrant\/Code\/yuanzihe\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(148): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))","#9 \/home\/vagrant\/Code\/yuanzihe\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Http\/Middleware\/CheckForMaintenanceMode.php(46): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))","#10 \/home\/vagrant\/Code\/yuanzihe\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(148): Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))","#11 \/home\/vagrant\/Code\/yuanzihe\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(102): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))","#12 \/home\/vagrant\/Code\/yuanzihe\/vendor\/dingo\/api\/src\/Http\/Middleware\/Request.php(127): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))","#13 \/home\/vagrant\/Code\/yuanzihe\/vendor\/dingo\/api\/src\/Http\/Middleware\/Request.php(103): Dingo\\Api\\Http\\Middleware\\Request->sendRequestThroughRouter(Object(Dingo\\Api\\Http\\Request))","#14 \/home\/vagrant\/Code\/yuanzihe\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(148): Dingo\\Api\\Http\\Middleware\\Request->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))","#15 \/home\/vagrant\/Code\/yuanzihe\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))","#16 \/home\/vagrant\/Code\/yuanzihe\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(102): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))","#17 \/home\/vagrant\/Code\/yuanzihe\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Http\/Kernel.php(149): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))","#18 \/home\/vagrant\/Code\/yuanzihe\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Http\/Kernel.php(116): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))","#19 \/home\/vagrant\/Code\/yuanzihe\/public\/index.php(53): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))","#20 {main}"]}}
  1. laravel details:
class RouteServiceProvider extends ServiceProvider {
    protected $namespace = 'App\Http\Controllers';
    protected $api_namespace = 'App\Http\Controllers\Api';

    public function map()
    {
        $this->mapApiRoutes();
        $this->mapWebRoutes();
    }

    protected function mapWebRoutes() {
        Route::middleware('web')
             ->namespace($this->namespace)
             ->group(base_path('routes/web.php'));
    }

    protected function mapApiRoutes() {
        $api = app('Dingo\Api\Routing\Router');
        $api->version('v1', function ($api) {
            require base_path('routes/api.php');
        });
    }
}
// api.php
<?php
Route::get('/home', 'HomeController@home');

I can not find any useful information to solve this problem - -. Your reply will be greatly appreciated!

Most helpful comment

php artisan api:cache solved the problem for me

All 5 comments

Having the same issue. At a first glance for me this is only happening on routes that I dont specify the "accept" header that includes the version. Luckily in my case its only 3 routes so it should be fairly straightforward in my case.

Will update if I figure out the root cause.

Having the same issue. Waiting for answers.

Please read the chapter 3. Creating API Endpoints to add your resource into some version (e.g. v1) group.
It's also helpful to check usable resources with command 'php artisan api:routes'.

I met the same issue and solved it by grouping my controller actions with version identifiers.

+1

php artisan api:cache solved the problem for me

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sukh-gill picture sukh-gill  路  3Comments

Sogl picture Sogl  路  4Comments

pedrolari picture pedrolari  路  3Comments

nghiepit picture nghiepit  路  4Comments

MicroDroid picture MicroDroid  路  3Comments