如何在Laravel 3中爲RESTful API創建路由?Laravel 3 - RESTful API
我想使用GET,PUT,POST和DELETE來創建一個API。
我希望所有的路線與/v1/
所以作爲前綴,我可以這樣做:
http://api.example.com/v1/controller/method/parameter
和剛剛創建相關的控制器檢查驗證和執行操作。
如何在Laravel 3中爲RESTful API創建路由?Laravel 3 - RESTful API
我想使用GET,PUT,POST和DELETE來創建一個API。
我希望所有的路線與/v1/
所以作爲前綴,我可以這樣做:
http://api.example.com/v1/controller/method/parameter
和剛剛創建相關的控制器檢查驗證和執行操作。
我建議您使用laravel 4而不是laravel 3. Laravel 4非常擅長創建RESTful API,並且您可以快速開始。下面是如何:如果你是新來的API
https://blog.apigee.com/detail/restful_api_design
他們認爲什麼是傳遞參數,像這樣
http://net.tutsplus.com/tutorials/php/laravel-4-a-start-at-a-restful-api/
而且觀看此視頻:api.test.com/v1/dogs?state = running
我最近開始使用laravel 4自己開發一個寧靜的API服務,到目前爲止它已經非常順利。另外laravel 4據說在五月發佈。
對於已經存在的路線,我會假定你需要在'before'前加上一個過濾器,然後將「url」加上前綴將其傳回原始路線。
所以在routes.php文件,是這樣的:
Route::get('login', '[email protected]', array('before' => 'guest'));
Route::post('login', '[email protected]', array('before' => 'guest'));
Route::get('logout', '[email protected]', array('before' => 'auth'));
Route::filter('before', function()
{
// Do stuff before every request to your application...
$url = "test";
$controller = "[email protected]";
$filter = array('before' => 'guest');
return Route::get('/v1/' . $url, $controller, $filter);
});
但我不知道你怎麼能在$網址,$控制器,與傳入請求$濾波器填補(也許支持::有東西)。
雖然我也是Laravel的新手,但還沒有研究過活動和過濾器。
哦,好的。我知道Laravel 4處於Beta版,但如果它在五月份發佈,我不妨開始使用它。謝謝,我會嘗試遵循nettuts +使用Laravel 4 – Jamesking56 2013-04-04 08:09:42