paqtcom / external-api-call-client
There is no license information available for the latest version (dev-main) of this package.
Setup code for making a client to an external API client
dev-main
2022-08-25 12:25 UTC
Requires
- php: >=8.1
- guzzlehttp/guzzle: ^7.4
- psr/http-message: ^1.0
Requires (Dev)
- jangregor/phpstan-prophecy: ^1.0
- phpspec/prophecy-phpunit: ^v2.0.1
- phpstan/phpstan: ^1.8.2
- phpunit/phpunit: ^9.5.23
- symfony/mime: 6.1.*
This package is not auto-updated.
Last update: 2025-05-03 00:41:16 UTC
README
Setup code for making a client to an external API.
Some very low-level classes used to structure calls to external API's. Internally this works like a state machine for API calls. And in every step the API call can fail.
Code usage:
Basically you use ExternalClient as base class and extend it and add functionality like this:
<?php use GuzzleHttp\Client; use PaqtCom\ExternalApiCallClient\Services\ExternalClient; use PaqtCom\ExternalApiCallClient\ErrorHandlers\ThrowExceptionOnError; class ExampleClient extends ExternalClient { public function __construct(Client $client) { parent::__construct(new JsonRequestFactory(), $client, new JsonResponseHandler(), new ThrowExceptionOnError(), new LogToDatabase()); } public function createOrder(OrderDto $order): OrderPlacedDto { return $this->post(new ExternalClientCall('Place order ' . $order->id, '/api/Order/' . $order->id , OrderPlacedDto::class), $order); } }
The ExternalClient makes the actual call and uses the ExternalClientCall to remember the current state of an API call.