Git Product home page Git Product logo

lib-rest-bundle's Introduction

PayseraRestBundle

Deprecated, use https://github.com/paysera/lib-api-bundle instead.

This bundle provides means for rapid API development.

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.

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 ...

lib-rest-bundle's People

Contributors

alexanderzaiets-paysera avatar andriisobolatpaysera avatar asteisiunas avatar desislavaggeorgieva avatar msprunskas avatar tomas7777 avatar tomasliubinas avatar vbartusevicius avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.