paqtcom / external-api-call-client
此包的最新版本(dev-main)没有可用的许可证信息。
创建外部API客户端的设置代码
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: 2024-09-20 21:56:00 UTC
README
创建外部API客户端的设置代码。
一些用于结构化对外部API调用的一些非常底层的类。在内部,这就像一个API调用的状态机。并且,在每一步中,API调用都可能失败。
代码使用
基本上,您使用ExternalClient作为基类,并扩展它并添加类似这样的功能
<?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); } }
ExternalClient执行实际调用,并使用ExternalClientCall来记住API调用的当前状态。