auto1-oss / service-api-client-bundle
Auto1 Service API Client for PHP projects
Package info
github.com/auto1-oss/service-api-client-bundle
Type:auto1-bundle
pkg:composer/auto1-oss/service-api-client-bundle
Requires
- php: ^7.4|^8.0
- auto1-oss/service-api-components-bundle: ^1.0
- auto1-oss/service-api-request: ^1.0
- monolog/monolog: ^1.22|^2.0|^3.0
- php-http/client-common: ^2.3
- php-http/discovery: ^1.3
- php-http/httplug: ^2.2
- php-http/message-factory: ^1.1
- psr/http-message: ^1.0
- psr/log: ^1.1|^2.0|^3.0
- symfony/config: ~5.0|~6.0|~7.0
- symfony/dependency-injection: ~5.0|~6.0|~7.0
- symfony/http-kernel: ~5.0|~6.0|~7.0
- symfony/monolog-bridge: ~5.0|~6.0|~7.0
- symfony/property-info: ~5.0|~6.0|~7.0
- symfony/security-core: ~5.0|~6.0|~7.0
- symfony/security-csrf: ~5.0|~6.0|~7.0
- symfony/security-http: ~5.0|~6.0|~7.0
- symfony/serializer: ~5.0|~6.0|~7.0
Requires (Dev)
- phpspec/prophecy: ^1.7.2
- phpunit/phpunit: ^8.5
- symfony/console: ~5.0|~6.0|~7.0
- symfony/phpunit-bridge: ^5.0|^6.0|^7.0
- symfony/yaml: ~5.0|~6.0|~7.0
This package is auto-updated.
Last update: 2026-07-23 15:13:15 UTC
README
Bundle uses php-http/httplug client abstraction. So you'll need to install some psr7-compatible client into your project to be used by this bundle. For more details: php-http/httplug clients and adapters.
This bundle builds requests via PSR-17 HTTP factories, discovered
with Http\Discovery\Psr17FactoryDiscovery. Your project therefore also needs a discoverable PSR-17
factory implementation (for example nyholm/psr7, or guzzlehttp/psr7 >= 2.0 — the PSR-17 factory
was introduced in Guzzle PSR-7 2.0, so 1.x is not enough).
Upgrade note:
Service\Request\RequestFactoryno longer depends on the abandonedphp-http/message-factory. Its constructor now takes PSR-17 factories (Psr\Http\Message\UriFactoryInterface,RequestFactoryInterface,StreamFactoryInterface) instead ofHttp\Message\UriFactory+Http\Message\MessageFactory. If you instantiate or re-register this service yourself, update the wiring — the container serviceauto1.api.message_factorywas replaced byauto1.api.request_factoryandauto1.api.stream_factory.
config.yml
auto1_service_api_client: request_visitors: - '@visitor1' - '@visitor2' strict_mode: false
- request_visitors - Request visitors (RequestVisitorInterface) are aimed to modify your Request - like adding custom headers. You can also TAG services with 'auto1.api.request_visitor' to make them visitors. Warning! By setting this configuration you will override default values!
- strict_mode - boolean,
falseby default. If it istruethe request factory ignores any request body for GET, HEAD, OPTIONS and TRACE HTTP methods. In other words, client will always send such requests without body.
Example of EP definition (yaml):
postUnicorn: method: 'POST' baseUrl: 'http://google.com' path: '/v1/unicorn' requestFormat: 'url' requestClass: 'Auto1\ServiceDTOCollection\Unicorns\Request\PostUnicorn' responseClass: 'Auto1\ServiceDTOCollection\Unicorns\Response\Unicorn' listUnicorns: method: 'GET' baseUrl: 'http://google.com' path: '/v1/unicorns' requestFormat: 'json' requestClass: 'Auto1\ServiceDTOCollection\Unicorns\Request\SearchUnicorns' responseClass: 'Auto1\ServiceDTOCollection\Unicorns\Response\Unicorn[]'
Example of ServiceRequest implementation:
class PostUnicorn implements ServiceRequestInterface { private $horn; public function setHorn(string $horn): self { $this->horn = $horn; return $this; } public function getHorn() { return $this->horn; } }
Example of Repository implementation:
class UnicornRepository { public function __construct(APIClientInterface $apiClient,) { $this->apiClient = $apiClient; } /** * @param string $horn * * @return Unicorn[] */ public function getListByHorn(string $horn): array { $serviceRequest = (new GetUnicornsByHornRequest())->setHorn($horn); return $this->apiClient->send($serviceRequest); } }
For more info - have a look at service-api-components-bundle usage: