2017 © Pedro Peláez
 

library lib-rest-bundle

Helps easily convert your regular controller to RESTful controller

image

paysera/lib-rest-bundle

Helps easily convert your regular controller to RESTful controller

  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 5 Forks
  • 0 Open issues
  • 22 Versions
  • 21 % Grown

The README.md

PayseraRestBundle

Deprecated, use https://github.com/paysera/lib-api-bundle instead., (*1)

This bundle provides means for rapid API development., (*2)

Installation

  • Download bundle: composer require paysera/lib-rest-bundle
  • Enable bundle:
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Paysera\Bundle\RestBundle\PayseraRestBundle(),
        );

        // ...
    }
}

Configuration

  • Example of the full bundle configuration
paysera_rest:
    property_path_converter: 'my_custom_path_converter' # Overrides the default path converter
    locales: ['en', 'ru', 'lt'] # Optional list of accepted locales

Basic Usage

  • Create and configure your controller:
class ApiController
{

    public function saveData(Data $data)
    {
        ...
        return new CustomResponseEntity();
    }
}
<service id="app_bundle.controller.api_controller" class="AppBundle\Controller\ApiController" public="true">
    ...
</service>
  • Create API service:
<service id="app_bundle.service.api_service" class="Paysera\Bundle\RestBundle\RestApi">
    <tag name="paysera_rest.api" api_key="my_custom_api_key"/>
    <argument type="service" id="service_container"/>
    <argument type="service" id="logger"/>
</service>
  • Configure your routing and add api_key:
<route id="my_api_route.post_data" path="/resource" methods="POST">
    <default key="_controller">app_bundle.controller.api_controller:saveData</default>
    <default key="api_key">my_custom_api_key</default>
</route>
  • Optionally, add request and response mappers to your API service:
<service id="app_bundle.service.api_service" class="Paysera\Bundle\RestBundle\RestApi">
    <tag name="paysera_rest.api" api_key="my_custom_api_key"/>
    <argument type="service" id="service_container"/>
    <argument type="service" id="logger"/>

    <call method="addRequestMapper">
        <argument>app_bundle.normalizer.data</argument>
        <argument>app_bundle.controller.api_controller:saveData</argument>
        <argument>data</argument>
    </call>

    <call method="addResponseMapper">
        <argument>app_bundle.normalizer.custom_response</argument>
        <argument>app_bundle.controller.api_controller:saveData</argument>
    </call>
</service>

Here app_bundle.normalizer.data is a service implementing \Paysera\Component\Serializer\Normalizer\DenormalizerInterface, app_bundle.normalizer.custom_response is a service implementing \Paysera\Component\Serializer\Normalizer\NormalizerInterface. Both of these services must be configured as public in their service definitions., (*3)

Testing

php7.4

docker build -t lib-rest7.4 -f docker/Dockerfile_PHP7.4 .
docker run -it -u $UID -v $PWD:/app -w /app lib-rest7.4 composer i
docker run -it -u $UID -v $PWD:/app -w /app lib-rest7.4 bin/phpunit

php8.0

docker build -t lib-rest8.0 -f docker/Dockerfile_PHP8.0 .
docker run -it -u $UID -v $PWD:/app -w /app lib-rest8.0 composer i
docker run -it -u $UID -v $PWD:/app -w /app lib-rest8.0 bin/phpunit

debugging

php7.4

docker run --add-host=host.docker.internal:host-gateway -e XDEBUG_MODE=debug -it -u $UID -v $PWD:/app -w /app lib-rest7.4 ...

php8.0

docker run --add-host=host.docker.internal:host-gateway -e XDEBUG_MODE=debug -it -u $UID -v $PWD:/app -w /app lib-rest8.0 ...

The Versions

09/04 2018

dev-master

9999999-dev

Helps easily convert your regular controller to RESTful controller

  Sources   Download

The Requires

 

The Development Requires

09/04 2018

4.0.1

4.0.1.0

Helps easily convert your regular controller to RESTful controller

  Sources   Download

The Requires

 

The Development Requires

05/04 2018

4.0.0

4.0.0.0

Helps easily convert your regular controller to RESTful controller

  Sources   Download

The Requires

 

The Development Requires

05/03 2018

3.0.3

3.0.3.0

Helps easily convert your regular controller to RESTful controller

  Sources   Download

The Requires

 

The Development Requires

19/12 2017

3.0.2

3.0.2.0

Helps easily convert your regular controller to RESTful controller

  Sources   Download

The Requires

 

The Development Requires

03/11 2017

3.0.1

3.0.1.0

Helps easily convert your regular controller to RESTful controller

  Sources   Download

The Requires

 

The Development Requires

22/09 2017

3.0.0

3.0.0.0

Helps easily convert your regular controller to RESTful controller

  Sources   Download

The Requires

 

The Development Requires

11/09 2017

2.1.0

2.1.0.0

Helps easily convert your regular controller to RESTful controller

  Sources   Download

The Requires

 

The Development Requires

31/08 2017

2.0.3

2.0.3.0

Helps easily convert your regular controller to RESTful controller

  Sources   Download

The Requires

 

The Development Requires

25/08 2017

2.0.2

2.0.2.0

Helps easily convert your regular controller to RESTful controller

  Sources   Download

The Requires

 

The Development Requires

25/08 2017

2.0.1

2.0.1.0

Helps easily convert your regular controller to RESTful controller

  Sources   Download

The Requires

 

The Development Requires

25/08 2017

2.0.0

2.0.0.0

Helps easily convert your regular controller to RESTful controller

  Sources   Download

The Requires

 

The Development Requires

16/08 2017

1.5.0

1.5.0.0

Helps easily convert your regular controller to RESTful controller

  Sources   Download

The Requires

 

The Development Requires

26/06 2017

1.4.0

1.4.0.0

Helps easily convert your regular controller to RESTful controller

  Sources   Download

The Requires

 

The Development Requires

13/04 2017

1.3.2

1.3.2.0

Helps easily convert your regular controller to RESTful controller

  Sources   Download

The Requires

 

The Development Requires

11/04 2017

1.3.0

1.3.0.0

Helps easily convert your regular controller to RESTful controller

  Sources   Download

The Requires

 

The Development Requires

11/04 2017

1.3.1

1.3.1.0

Helps easily convert your regular controller to RESTful controller

  Sources   Download

The Requires

 

The Development Requires

09/03 2017

1.2.1

1.2.1.0

Helps easily convert your regular controller to RESTful controller

  Sources   Download

The Requires

 

The Development Requires

07/02 2017

1.2.0

1.2.0.0

Helps easily convert your regular controller to RESTful controller

  Sources   Download

The Requires

 

The Development Requires

03/02 2017

1.1.0

1.1.0.0

Helps easily convert your regular controller to RESTful controller

  Sources   Download

The Requires

 

The Development Requires

21/12 2016

1.0.1

1.0.1.0

Helps easily convert your regular controller to RESTful controller

  Sources   Download

The Requires

 

The Development Requires

15/12 2016

1.0.0

1.0.0.0

Helps easily convert your regular controller to RESTful controller

  Sources   Download

The Requires

 

The Development Requires