devfactory/api
最新稳定版本:1.0.5
Composer 安装命令:
composer require devfactory/api
包简介
RESTful API package
README 文档
README
Helpers to create an API for laravel 4.2
This module handle json and xml as response
##How to setup
update composer.json file:
{
"require": {
"devfactory/api": "1.0.*"
}
}
and run composer update from terminal to download files.
update app.php file in app/config directory:
'providers' => array( 'Devfactory\Api\ApiServiceProvider', ),
alias => array( 'API' => 'Devfactory\Api\Facades\ApiFacade', ),
##Configuration
php artisan config:publish devfactory/api
##How to use api in your route
the param {format} are not mandatory
Route::group(array('prefix' => 'v1'), function() { Route::get('foo.{format}', 'ApiV1\FooController@foo'); Route::post('bar.{format}', 'ApiV1\FooController@bar'); }); Route::group(array('prefix' => '{format}/v1'), function() { Route::get('foo', 'ApiV1\FooController@foo'); Route::post('bar', 'ApiV1\FooController@bar'); });
In you controller you can use
return Response::api(array("foo" => "bar"), 404); return Response::api(array("ok"));
or
return API::createResponse(array("foo" => "bar"), 404); return API::createResponse(array("ok"));
##To call your service you can use the Facade
API::get('v1/foo.json', array('foo' => 'bar')); API::post('v1/bar.xml', array('foo' => 'bar')); API::put('v1/bar.xml', array('foo' => 'bar'));
统计信息
- 总下载量: 604
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-12-08