实现API Rest服务我正面临着url签名如何/在哪里通过API版本的问题。Laravel路由:如何在uri中添加可选参数?
通过阅读周围,我决定通过的版本一样
http://mydomainservice.tld/api/version/entity ...
关于治疗版本可选的解析请求指为最新版本的API,这将是意向:
http://mydomainservice.tld/version/entity ...
的问题不是如何管理/安排API休息版本,但更多的,如果有实现路由规则前面加上一个可选比肩的机会ameter在URI:
这是工作:
Route::group(['prefix' => 'api/'], function(){
Route::get('{v}/subscribers', '[email protected]');
Route::get('subscribers', '[email protected]);
});
对于像两个电话:
http://mydomain.tld/api/subscribers http://mydomain.tld/api/1/subscribers
但我想解决它在一个单一的规则:
Route::get('{v?}/subscribers', '[email protected]');
但是这第二条规则w本身,如果我尝试on't工作,请求等伸手:
http://mydomain.tld/api/subscribers
感谢您的确认,以及肮脏的解决方案:-) – koalaok