yusefauto1 / service-api-client-bundle
Auto1 Service API Client for PHP projects
Installs: 79
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 18
Type:auto1-bundle
Requires
- php: >=7.0.8
- auto1-oss/service-api-request: ^1.0
- monolog/monolog: ~1.22
- php-http/client-common: ^1.5
- php-http/discovery: ^1.7
- php-http/httplug: ^1.1
- psr/http-message: ^1.0
- psr/log: ^1.1
- symfony/config: ^2.7.39
- symfony/dependency-injection: ^2.7.39
- symfony/http-kernel: ^2.7.39
- symfony/monolog-bridge: ^2.7.39
- symfony/property-info: ^2.8
- symfony/security: ^2.7.39
- symfony/serializer: ^2.7.39
- yusefauto1/service-api-components-bundle: ^1.0.2
Requires (Dev)
- phpspec/prophecy: ^1.7.2
- phpunit/phpunit: ^4.8
- symfony/console: ^2.7.39
- symfony/phpunit-bridge: ^2.7.39
- symfony/yaml: ^2.7.39
This package is not auto-updated.
Last update: 2025-03-04 09:02:20 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.
config.yml
auto1_service_api_client: request_visitors: - '@visitor1' - '@visitor2'
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!
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: