twentytwo-labs / api-service-bundle
Integrate API Service into Symfony
Installs: 90
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=8.0
- ext-json: *
- nyholm/psr7: ^1.5
- php-http/httplug: ^2.4
- php-http/promise: ^1.2
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
- psr/http-message: ^2.0
- symfony/framework-bundle: ^5.0 || ^6.0 || ^7.0
- symfony/serializer: ^5.0 || ^6.0 || ^7.0
- twentytwo-labs/api-validator: ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.4
- infection/infection: ^0.28
- matthiasnoback/symfony-dependency-injection-test: ^5.0
- phpstan/phpstan: ^1.11
- phpstan/phpstan-deprecation-rules: ^1.2
- phpstan/phpstan-phpunit: ^1.4
- phpunit/phpunit: ^10.4
- squizlabs/php_codesniffer: ^3.4
- symfony/http-client: ^5.0 || ^6.0 || ^7.0
Suggests
- cache/adapter-bundle: Integrate cache pool providers in Symfony <3.1
- php-http/guzzle7-adapter: HttpClient adapter using Guzzle7
- php-http/httplug-bundle: Integrate HTTP Clients into Symfony
- symfony/http-client: Integrate HTTP Clients into Symfony
README
This bundle integrate the API Service Component into Symfony.
Installation
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
composer require twentytwo-labs/api-service-bundle
Then, enable the bundle by adding the following line in the app/AppKernel.php file of your project:
<?php // app/AppKernel.php class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new TwentytwoLabs\ApiServiceBundle\ApiServiceBundle(), ); // ... } }
Config
Full configuration provided by the bundle:
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.
You can use your own HTTP client services within Symfony, but we strongly advice you to use the HttplugBundle
composer require php-http/httplug-bundle
You can then choose one the many HTTP client adapter supported by HTTPlug. A list is available here
# 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.
For performance reasons, the cache SHOULD be enable in production.
From Symfony 4.0 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.