cego / service-client-base
此包已被废弃且不再维护。未建议替代包。
包含各种特定客户端实现工具和抽象的包
0.1.10
2021-06-24 12:00 UTC
Requires
- php: ^7.4|^8.0
- ext-json: *
- guzzlehttp/guzzle: ^6.5.5|^7.0.1
- illuminate/http: ^7.0|^8.0
- illuminate/support: ^7.0|^8.0
- phpoption/phpoption: ^1.7
- vlucas/phpdotenv: ^5.2
Requires (Dev)
- cego/request-insurance: ^0.1.3
- friendsofphp/php-cs-fixer: ^2.16
- orchestra/testbench: ^6.13
- phpstan/phpstan: ^0.12
- phpunit/phpunit: ^9.0
Suggests
- cego/request-insurance: Allows for sending asynchronous requests
- dev-main
- 0.1.10
- 0.1.9
- 0.1.8
- 0.1.7
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- 0.0.5
- 0.0.4
- 0.0.3
- 0.0.2
- 0.0.1
- dev-niza/retry-timeouts-and-catch-them-correctly
- dev-niza/add-headers-to-the-response-object
- dev-niza/do-not-retry-client-errors
- dev-niza/add-request-logging
- dev-niza/show-full-url-on-error
- dev-thwo/http-request-driver-must-handle-empty-response
- dev-thwo/remove-composer-lock
This package is auto-updated.
Last update: 2022-01-24 13:13:19 UTC
README
包含各种特定客户端实现工具和抽象的项目
该项目最初由
- Niki Ewald Zakariassen (NIZA)
使用方法
抽象服务客户端提供与服务交互的基本流体接口。
扩展 AbstractServiceClient
use Cego\ServiceClientBase\AbstractServiceClient; use Cego\ServiceClientBase\RequestDrivers\Response; class YourServiceClient extends AbstractServiceClient { public function myGetRequestEndpoint(array $queryParameters = [], array $options = []): Response { return $this->getRequest('/my/get/endpoint', $queryParameters, $options); } public function myPostRequestEndpoint(array $data = [], array $options = []): Response { return $this->postRequest('/my/post/endpoint', $data, $options); } }
接口
// Getting a client instance YourServiceClient::create('service_base_url') ->auth('username', 'password');
// Using request insurance YourServiceClient::create('service_base_url') ->auth('username', 'password') ->useRequestInsurance();
注意:请求保险仅在 POST 请求中使用,并且会记住后续请求。GET 请求始终使用同步 HTTP 驱动程序 - 记得安装 cego/request-insurance 以启用此功能
错误处理
客户端不使用错误返回值,这意味着如果请求失败,则会抛出异常: ServiceRequestFailedException.php。
客户端在抛出异常之前,会在错误上配置重试次数。
- env("SERVICE_CLIENT_TIMEOUT")
- env("SERVICE_CLIENT_MAXIMUM_NUMBER_OF_RETRIES")
- env("SERVICE_CLIENT_RETRY_DELAY")