pcelta / contentnegotiation-service-provider

Content Negotiation Service Provider

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Content Negotiation Service Provider

Build Status Scrutinizer Code Quality Code Coverage HHVM Latest Stable Version Total Downloads License

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

####Response

Response Header: Content-Type: application/json
Status Code: 200
Body:
{
    "you data to response"
}


####Request

HTTP GET
Header: Accept: text/html

Response

Response Header: Content-Type: application/json
Status Code: 406
Body:
{
    "message":"Accept Type Not Acceptable"
}

License

MIT License

About

Content Negotiation Service Provider


Languages

Language:PHP 100.0%