cego/service-client-base

This package is abandoned and no longer maintained. No replacement package was suggested.

A package containing utility and abstractions for various specific clients implementations

0.1.10 2021-06-24 12:00 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")