cego / service-client-base
A package containing utility and abstractions for various specific clients implementations
Installs: 3 338
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 6
Forks: 0
Open Issues: 0
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
A project containing utility and abstractions for various specific clients implementations
Project was initially created by:
- Niki Ewald Zakariassen (NIZA)
Usage
The abstract service client supplies a base fluid interface for interacting with services.
Extend 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); } }
Interface
// Getting a client instance YourServiceClient::create('service_base_url') ->auth('username', 'password');
// Using request insurance YourServiceClient::create('service_base_url') ->auth('username', 'password') ->useRequestInsurance();
Note: Request insurance is only usable for POST requests, and is remembered for following requests. GET requests will always use the synchronous HTTP driver - Remember to install cego/request-insurance for enabling this feature
Error Handling
The client does not use error return values, meaning if a request failed then an exception will be thrown: ServiceRequestFailedException.php.
The client has a configurable amount of retries on errors, before throwing an exception.
- env("SERVICE_CLIENT_TIMEOUT")
- env("SERVICE_CLIENT_MAXIMUM_NUMBER_OF_RETRIES")
- env("SERVICE_CLIENT_RETRY_DELAY")