Configure HTTP Transport
The PHP-SDK does not specify a dependency on any HTTP client to ensure better integration with existing systems and frameworks. Instead, the PHP HTTP Discovery package is used to allow us to detect a compatible HTTP client where required.
If your application does not already use a PSR-18 compatible client, you will need to install one before sending data to Klevu's APIs. We recommend using Guzzle, which can be installed with the following command
composer install guzzlehttp/guzzleAll services which interact with Klevu's APIs accept a HTTP client instance via their constructor.
Note: If you are integrating into a modern framework, you should implement this via your dependency injection system even if automatic discovery succeeds to ensure better stability and application performance.
<?php
declare(strict_types=1);
use GuzzleHttp\Client;
use Klevu\PhpSDK\Service\Account\AccountFeaturesService;
use Klevu\PhpSDK\Service\Account\AccountLookupService;
use Klevu\PhpSDK\Service\Account\UpdateStoreFeedUrlService;
use Klevu\PhpSDK\Service\Analytics\CollectService as AnalyticsCollectService;
use Klevu\PhpSDK\Service\Indexing\AttributesService;
use Klevu\PhpSDK\Service\Indexing\Batch\DeleteService as BatchDeleteService;
use Klevu\PhpSDK\Service\Indexing\BatchService;
$httpClient = new Client();
// Account
$accountFeatureService = new AccountFeaturesService(
httpClient: $httpClient,
);
$accountLookupService = new AccountLookupService(
httpClient: $httpClient,
);
$updateStoreFeedUrlService = new UpdateStoreFeedUrlService(
httpClient: $httpClient,
);
// Analytics
$collectService = new AnalyticsCollectService(
httpClient: $httpClient,
);
// Indexing
$attributesService = new AttributesService(
httpClient: $httpClient,
);
$batchService = new BatchService(
httpClient: $httpClient,
);
$batchDeleteService = new BatchDeleteService(
httpClient: $httpClient,
);