2017 © Pedro Peláez
 

library rest-service-provider

A Rest Service Provider for Silex 2.0

image

euskadi31/rest-service-provider

A Rest Service Provider for Silex 2.0

  • Wednesday, October 21, 2015
  • by euskadi31
  • Repository
  • 1 Watchers
  • 0 Stars
  • 396 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 14 Versions
  • 5 % Grown

The README.md

Silex Rest Service Provider

Build Status SensioLabs Insight Coveralls HHVM Packagist, (*1)

Adding some REST capabilities to Silex 2.0, so you can more easily build RESTful APIs., (*2)

Install

Add euskadi31/rest-service-provider to your composer.json:, (*3)

% php composer.phar require euskadi31/rest-service-provider:~1.2

Usage

Configuration

<?php

$app = new Silex\Application;

$app->register(new \Euskadi31\Silex\Provider\RestServiceProvider);

Field filter

<?php

$app = new Silex\Application;

$app->register(new \Euskadi31\Silex\Provider\RestServiceProvider);

$app->get('/users', function() {
    return $this->json([
        [
            'id'        => 1,
            'username'  => 'John',
            'email'     => 'john@example.com',
            'enabled'   => true
        ],
        [
            'id'        => 2,
            'username'  => 'Jean',
            'email'     => 'jean@example.com',
            'enabled'   => true
        ]
    ]);
});

Request:, (*4)

GET /users?fields=username

Response:, (*5)

[
    {
        "id": 1,
        "username": "John"
    },
    {
        "id": 2,
        "username": "Jean"
    }
]

Jsonp response

<?php

$app = new Silex\Application;

$app->register(new \Euskadi31\Silex\Provider\RestServiceProvider);

$app->get('/users', function() {
    return $this->json([
        [
            'id'        => 1,
            'username'  => 'John',
            'email'     => 'john@example.com',
            'enabled'   => true
        ],
        [
            'id'        => 2,
            'username'  => 'Jean',
            'email'     => 'jean@example.com',
            'enabled'   => true
        ]
    ]);
});

Request:, (*6)

GET /users?callback=Acme.process

Response:, (*7)

/**/Acme.process([
    {
        "id": 1,
        "username": "John",
        "email": "john@example.com",
        "enabled": true
    },
    {
        "id": 2,
        "username": "Jean",
        "email": "jean@example.com",
        "enabled": true
    }
]);

Pretty print response

<?php

$app = new Silex\Application;

$app->register(new \Euskadi31\Silex\Provider\RestServiceProvider);

$app->get('/users', function() {
    return $this->json([
        [
            'id'        => 1,
            'username'  => 'John',
            'email'     => 'john@example.com',
            'enabled'   => true
        ],
        [
            'id'        => 2,
            'username'  => 'Jean',
            'email'     => 'jean@example.com',
            'enabled'   => true
        ]
    ]);
});

Request:, (*8)

GET /users?pretty=0

Response:, (*9)

[{"id":1,"username":"John","email":"john@example.com","enabled":true},{"id":2,"username":"Jean","email":"jean@example.com","enabled":true}]

Error response

{
    "error": {
        "message": "No route found for \u0022GET \/me1\u0022",
        "type": "NotFoundHttpException",
        "code": 404
    }
}

License

RestServiceProvider is licensed under the MIT license., (*10)

The Versions

21/10 2015
21/10 2015
24/09 2015
14/08 2015

v1.2.7

1.2.7.0

A Rest Service Provider for Silex 2.0

  Sources   Download

MIT

The Requires

 

The Development Requires

13/08 2015

v1.2.6

1.2.6.0

A Rest Service Provider for Silex 2.0

  Sources   Download

MIT

The Requires

 

The Development Requires

07/08 2015

v1.2.5

1.2.5.0

A Rest Service Provider for Silex 2.0

  Sources   Download

MIT

The Requires

 

The Development Requires

07/08 2015

v1.2.4

1.2.4.0

A Rest Service Provider for Silex 2.0

  Sources   Download

MIT

The Requires

 

The Development Requires

06/08 2015

v1.2.3

1.2.3.0

A Rest Service Provider for Silex 2.0

  Sources   Download

MIT

The Requires

 

The Development Requires

06/08 2015

v1.2.2

1.2.2.0

A Rest Service Provider for Silex 2.0

  Sources   Download

MIT

The Requires

 

The Development Requires

06/08 2015

v1.2.1

1.2.1.0

A Rest Service Provider for Silex 2.0

  Sources   Download

MIT

The Requires

 

The Development Requires

05/08 2015

v1.2.0

1.2.0.0

A Rest Service Provider for Silex 2.0

  Sources   Download

MIT

The Requires

 

The Development Requires

30/06 2015

v1.1.1

1.1.1.0

A Rest Service Provider for Silex 2.0

  Sources   Download

MIT

The Requires

 

The Development Requires

29/06 2015

v1.1

1.1.0.0

A Rest Service Provider for Silex 2.0

  Sources   Download

MIT

The Requires

 

The Development Requires

19/06 2015

v1.0

1.0.0.0

A Rest Service Provider for Silex 2.0

  Sources   Download

MIT

The Requires

 

The Development Requires