lokhman/silex-restful
Composer 安装命令:
composer require lokhman/silex-restful
包简介
Silex 2.0+ service provider for RESTful middleware
README 文档
README
RESTful middleware service provider for Silex 2.0+ micro-framework.
This project is a part of
silex-toolslibrary.
Installation
You can install silex-restful with Composer:
composer require lokhman/silex-restful
Documentation
Registering RestfulServiceProvider will easily extend your application routing with JSON request/response methods,
error handing and JSON parameter acceptance. It works in the same way as Silex routing binding (get, post, etc),
supports own controllers_factory and mount functionality.
use Lokhman\Silex\Provider\RestfulServiceProvider;
$app->register(new RestfulServiceProvider());
// response is transformed to JSON string
$app['restful']->get('/api', function() {
return ['version' => '1.0'];
});
// can mount controller collections
$app['restful']->mount('/api/v2', function($api) {
// accepts parameters from "application/json" body
$api->post('/submit', function(Request $request) {
return ['params' => $request->request->all()];
});
});
// can mount controller providers
class ApiBundle implements ControllerProviderInterface {
function connect(Application $app) {
$factory = $app['restful.controllers_factory'];
$factory->get('/', function() {
// will modify all exceptions to JSON compatible responses
throw new GoneHttpException('API v3 is not supported anymore.');
});
return $factory->getControllerCollection();
}
}
$app->mount('/api/v3', new ApiBundle());
License
Library is available under the MIT license. The included LICENSE file describes this in detail.
统计信息
- 总下载量: 375
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2017-01-24