2017 © Pedro Peláez
 

symfony-bundle api-service-bundle

Integrate API Service into Symfony

image

eleven-labs/api-service-bundle

Integrate API Service into Symfony

  • Wednesday, June 6, 2018
  • by guillemcanal
  • Repository
  • 4 Watchers
  • 1 Stars
  • 127 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 7 Versions
  • 46 % Grown

The README.md

API Service Bundle

Build Status Code Coverage Scrutinizer Quality Score, (*1)

This bundle integrate the API Service Component into Symfony., (*2)

Installation

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:, (*3)

composer require eleven-labs/api-service-bundle

Then, enable the bundle by adding the following line in the app/AppKernel.php file of your project:, (*4)

<?php
// app/AppKernel.php
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new ElevenLabs\ApiServiceBundle\ApiServiceBundle(),
        );
        // ...
    }
}

Config

Full configuration provided by the bundle:, (*5)

api_service:
  # (optional)
  default_services:
    client: httplug.client
    message_factory: httplug.message_factory
    uri_factory: httplug.uri_factory
  # (optional) cache schema files
  cache:
    # provide the Id of any PSR-6 cache service
    service: 'my_app.cache'
  # (optional) configure supported pagination providers
  pagination:
    # extract pagination from response headers
    header:
      page: X-Page
      perPage: X-Per-Page
      totalPages: X-Total-Pages
      totalItems: X-Total-Items
  # configure api services
  apis:
    my_service:
      # the schema describing your api
      schema: 'file://%kernel.root_dir%/config/schema/foo.yml'
      # (optional) use a specific http client implementation
      client: httplug.client.foo
      # (optional) fine tune your api service
      config:
        # provide a base url
        baseUri: https://bar.com
        # validate request
        validateRequest: true
        # validate response
        validateResponse: false
        # return a psr-7 response
        # by default it return a `Resource` class
        returnResponse: false

Dependencies

HTTP client

The Api Service component make use of the Http\Client\HttpClient interface provided by HttPlug to send requests., (*6)

You can use your own HTTP client services within Symfony, but we strongly advice you to use the HttplugBundle, (*7)

composer require php-http/httplug-bundle

You can then choose one the many HTTP client adapter supported by HTTPlug. A list is available here, (*8)

# for example, here we choose the Guzzle 6 adapter
composer require php-http/guzzle6-adapter

Cache

This bundle have the ability to cache schema files used by you API services.
It use the PSR-6: Caching Interface to do so., (*9)

For performance reasons, the cache SHOULD be enable in production., (*10)

From Symfony 3.1 and above

Symfony 3.1 provide a cache implementation of the PSR-6 Caching Interface. You don't need additional components to integrate caching capabilities to the framework., (*11)

From Symfony 2.7 to 3.1

We recommend you to use the PSR-6 Cache adapter Bundle., (*12)

You can then choose one of the many cache pool implementations provided by the php-cache organization., (*13)

The Versions