API Service
, (*1)
This component read API service descriptions written
in OpenAPi/Swagger 2.0
in order serialize requests, and parse responses into easy to use model structures., (*2)
Dependencies
This component rely on well known interfaces that discribe:, (*3)
Installation
This library can be easily installed via composer, (*4)
composer require eleven-labs/api-service
Usage
In order to consume an API, you will need to write an API service description., (*5)
As of now, we only support swagger files, but we plan to support RAML 1.0 and Api Blueprint in
a near future., (*6)
For standalone projects usage of the provided builder is encouraged:, (*7)
<?php
$apiService = ElevenLabs\Api\Service\ApiServiceBuilder::create()->build('file:///absolute/path/to/your/schema.json');
$operationId = 'getSomething';
$parameters = ['foo' => 'bar'];
// A Synchronous Request
/** @var \ElevenLabs\Api\Service\Resource\Resource $resource */
$resource = $apiService->call($operationId, $parameters);
// An Asynchronous Request
$promise = $apiService->callAsync($operationId, $parameters);
/** @var \ElevenLabs\Api\Service\Resource\Resource $resource */
$resource = $promise->wait();
Important: You MUST provide an operationId for each
paths described in your swagger file., (*8)
Builder Dependencies
You will need one of the HttpClient adapter
provided by HttPlug and the HTTP Client Discovery Service., (*9)
# install the discivery service
composer require php-http/discovery
# install one of the http client adapter (here, we use the guzzle6 adapter)
composer require php-http/guzzle6-adapter
Builder configuration
The builder provide additional methods to fine tune your API Service:, (*10)
-
withCacheProvider(CacheItemPoolInterface $cacheProvider), (*11)
Cache the API service description using a PSR-6: Cache Interface, (*12)
-
withHttpClient(HttpClient $httpClient), (*13)
Provide an HttpClient implementing the Http\Client\HttpClient interface.
By default, it will use the Http\Discovery\HttpClientDiscovery::find() method, (*14)
-
withMessageFactory(MessageFactory $messageFactory), (*15)
Provide a MessageFactory implementing the Http\Message\MessageFactory interface.
By default, it will use the Http\Discovery\MessageFactoryDiscovery::find() method, (*16)
-
withUriFactory(UriFactory $uriFactory), (*17)
Provide an UriFactory implementing the Http\Message\UriFactory interface.
By default, it will use the Http\Discovery\UriFactory::find() method, (*18)
-
withSerializer(SerializerInterface $serializer), (*19)
Provide a Serializer.
By default, it will use the Symfony Serializer., (*20)
-
withEncoder(EncoderInterface $encoder), (*21)
Add an encoder to encode Request body and decode Response body.
By default, it register Symfony's JsonEncoder and XmlEncoder., (*22)
-
withPaginationProvider(PaginationProvider $paginatorProvide), (*23)
When using the default ResourceDenormalizer, you can provide a pagination provider to add
pagination informations into Collection objects. Available implementations can be found in the
src/Pagination/Provider folder. You can create your own by implementing
the ElevenLabs\Api\Service\Pagination\PaginationProvider interface., (*24)
-
withDenormalizer(NormalizerInterface $normalizer), (*25)
Add a denormalizer used to denormalize Response decoded body.
By default, it use the ElevenLabs\Api\Service\Denormalizer\ResourceDenormalizer that denormalize
a Response into a Resource object. A Resource object can be an Item or a Collection., (*26)
-
withBaseUri($baseUri), (*27)
Provide a base URI from which your API is exposed.
By default, it will use your the schemes key and host key defined in your API service description., (*28)
-
disableRequestValidation(), (*29)
Disable Request validation against your API service description.
Enabled by default, (*30)
-
enableResponseValidation(), (*31)
Enable Response validation against your API service description.
Disabled by default., (*32)
-
returnResponse(), (*33)
Return a PSR-7 Response when using ApiService call() and callAsync() methods instead of a denormalized object., (*34)
-
setDebug($bool), (*35)
Enable debug mode.
When enabled, it will expire the schema cache immediatly if a cache implementation is provided
using the withCacheProvider(CacheItemPoolInterface $cacheProvider) method., (*36)