kununu/rest-api-bundle

There is no license information available for the latest version (4.1.0) of this package.

This is a wrapper for mediamonks/rest-api-bundle adding kununu specific functionality.

This package's canonical repository appears to be gone and the package has been frozen as a result.

Installs: 11 760

Dependents: 1

Suggesters: 0

Security: 0

Stars: 1

Watchers: 16

Forks: 0

Open Issues: 4

Type:symfony-bundle


README

This is a wrapper for mediamonks/rest-api-bundle to support custom Kununu requirements.

Configuration

For all configuration options please follow the original bundle.

Note

Since this is a wrapper of MediaMonks Rest API Bundle, the configuration name stays unchanged: mediamonks_rest_api

Installation

Step 1: Add custom private repositories to composer.json

...
"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/kununu/symfony-rest-api-bundle.git",
		"no-api": true
    },
],

Step 2: Install the bundle

Open a command console, enter your project directory and execute:

$ composer require kununu/rest-api-bundle:^4.0

For applications that don't use Symfony Flex

Step 2.1: Enable the bundle

// app/ApisKernel.php
class ApiKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            // ...
            new Kununu\RestApiBundle\KununuRestApiBundle(),
        ];
    }
}

Step 3: Configuration

# config/config.yml
...
# MediaMonks Rest API bundle
mediamonks_rest_api:
    serializer: JMS
    request_matcher:
        whitelist: [~^/~]

Important note!

Since this requires the Kununu Monolog Bundle be sure to also configure the application name in your configuration:

# config/config.yml
...
kununu_monolog:
  processors:
    application: APPLICATION_NAME

AWS Trusted Proxies Request Listener

In order to get the Client IP Address properly on services behind the Cloudfront in AWS environment, AwsTrustedProxiesRequestListener.php was added. Listener is disabled by default and must be enabled in the config:

Important note!

If you are requesting the service from an another service, e.g. BFF, you need to set both CLOUDFRONT and AMAZON in aws_service_list: ['CLOUDFRONT', 'AMAZON']

# config/config.yml
# MediaMonks Rest API bundle
mediamonks_rest_api:
    aws_trusted_proxies:
        enabled: true 
        cache_key: 'aws_trusted_proxies_ip_ranges'  # Not required 
        cache_ttl: 43200                            # Not required
        aws_services_list: ['CLOUDFRONT', 'AMAZON']           # Not required

AWS Trusted Proxies - import command

To improve the performance of the AWS Trusted Proxies feature, there is a command available to fetch the Trusted proxies and save them to the app cache during the container start. You can simply add the command into your bin/run_startup.sh:

# bin/run_startup.sh

cd $(dirname $PWD/$0)

php console kununu:import-aws-trusted-proxies

JMS Serializer Context Response

Support for JMS Serializer SerializationContext was added to enable the possibility of using the Serialization groups and versions provided by JMS Serializer.

Usage is simple and requires an usage of a new ContextJsonResponse:

// ApiBundle\Controller\IndexController.php

namespace ApiBundle\Controller;

use ApiBundle\ExampleEntity;
use JMS\Serializer\SerializationContext;
use JMS\Serializer\SerializerInterface;
use Kununu\RestApiBundle\Response\ContextJsonResponse;

class IndexController
{
    public function IndexAction()
    {
        $data = [
            'entity' => new ExampleEntity(),
        ];
        
        return new ContextJsonResponse($data, SerializationContext::create()->setGroups(['Default', 'group1', 'group2']));
    }
}

Kununu legacy response model

If the service needs to use our legacy response model, you can use KununuLegacyResponseModel included in this bundle.

# config/config.yml
# MediaMonks Rest API bundle
mediamonks_rest_api:
    response_model: kununu_legacy

Custom Response Model

You can also use a custom ResponseModel by implementing MediaMonks\RestApi\Model\ResponseModelInterface

// ApiBundle\Model\CustomResponseModel

namespace ApiBundle\Model;

use MediaMonks\RestApi\Model\ResponseModelInterface;

class CustomResponseModel implements ResponseModelInterface
{
    // your code
}

Configuration

First, register the Response model as a service

# config/services.yml
...
services:
    app.kununu_response_model:
        class: ApiBundleModel\Model\ResponseModelClass

Now use the service as an option in bundle config:

# config/config.yml
# MediaMonks Rest API bundle
mediamonks_rest_api:
    response_model: app.kununu_response_model