dafiti/contentnegotiation-service-provider
最新稳定版本:0.0.2
Composer 安装命令:
composer require dafiti/contentnegotiation-service-provider
包简介
A Silex Service Provider for Simple Content Negotiation
README 文档
README
A Silex Service Provider for Simple Content Negotiation.
Instalation
The package is available on Packagist. Autoloading is PSR-4 compatible.
{
"require": {
"dafiti/contentnegotiation-service-provider": "dev-master"
}
}
Usage
use Silex\Application; use Dafiti\Silex\ContentNegotiationServiceProvider; $config = [ 'available_accepts' => [ 'application/json', 'application/xml' ], 'default_accept' => 'application/json' ]; $app = new Application(); $app->register(new ContentNegotiationServiceProvider($config)); $app->get("/your-endpoint", function() { $data = ["you data to response"]; return new \Dafiti\Silex\Response($data); });
Request Examples:
Request
HTTP GET
Header: Accept: application/json
URL: http://baseurl.com/your-endpoint
####Response
Response Header: Content-Type: application/json
Status Code: 200
Body:
{
"you data to response"
}
####Request
HTTP GET
Header: Accept: text/html
URL: http://baseurl.com/your-endpoint
Response
Response Header: Content-Type: application/json
Status Code: 406
Body:
{
"message":"Accept Type Not Acceptable"
}
License
MIT License
统计信息
- 总下载量: 1.02k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-04-17