Skip to content

giggsey/ResponsibleServiceProvider

 
 

Repository files navigation

ResponsibleServiceProvider

A Silex ServiceProvider for automagic response formatting.

Build Status

Installation

  1. Add the package to you composer.json:

    "require": { "tobiassjosten/responsible-service-provider": "dev-master" }

  2. Run composer install.

  3. Register it in your application.

    use Tobiassjosten\Silex\ResponsibleServiceProvider; $app->register(new ResponsibleServiceProvider());

Usage

Once enabled, just have your controllers return your data in array format. ResponsibleServiceProvider will do the rest.

$app->get('/foo', function () {
    return ['Bar'];
});

In JSON:

$ curl -I -H 'Accept: application/json' http://example.com/foo
HTTP/1.1 200 OK
Date: Tue, 07 May 2013 08:30:58 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: PHP/5.4.9-4ubuntu2
Cache-Control: no-cache
Transfer-Encoding: chunked
Content-Type: application/json

["Bar"]

And in XML:

$ curl -I -H 'Accept: application/xml' http://example.com/foo
HTTP/1.1 200 OK
Date: Tue, 07 May 2013 08:30:58 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: PHP/5.4.9-4ubuntu2
Cache-Control: no-cache
Transfer-Encoding: chunked
Content-Type: application/xml

<?xml version="1.0"?>
<response><item key="0">Bar</item></response>

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%