composer require asm/eprel-api-client
use Asm\EprelApiClient\EprelClient;
$client = new EprelClient();
$results = $client->search()->byProductType('refrigerator')->execute();
$client->search() → Fluent builder for queries.$client->product($productId) → Fetch single product details.Use the fluent interface for complex searches:
$client->search()
->byProductType('washing_machine')
->byEnergyLabel('A')
->byEnergyEfficiencyClass('A+++')
->byManufacturer('Bosch')
->limit(10)
->execute();
AppServiceProvider:
public function register()
{
$this->app->singleton(EprelClient::class, function ($app) {
return new EprelClient(
httpClient: $app->make(\GuzzleHttp\Client::class),
cache: $app->make(\Illuminate\Contracts\Cache\Store::class)
);
});
}
EprelClient into controllers/services:
public function __construct(private EprelClient $eprel)
{
}
->nextPage() or iterate with ->getIterator().map:
$products = $this->eprel->search()->execute()->map(fn ($item) => [
'id' => $item['productId'],
'name' => $item['productName'],
]);
$client = new EprelClient(cache: $cacheStore, cacheTTL: 3600);
$cache->forget('eprel_product_' . $productId);
try/catch with EprelApiException:
try {
$client->product('123')->execute();
} catch (EprelApiException $e) {
report($e); // Log or notify
}
429 responses.API Rate Limits:
Deprecated Endpoints:
Type Safety:
array_key_first/array_key_exists carefully or extend the client to return DTOs:
class ProductDto {
public function __construct(
public string $productId,
public string $productName,
public ?string $energyLabel,
) {}
}
Cache Key Collisions:
eprel_. Customize if using shared cache (e.g., Redis):
$client = new EprelClient(cache: $cache, cachePrefix: 'myapp_eprel_');
$client = new EprelClient(httpClient: new \GuzzleHttp\Client([
'handler' => \GuzzleHttp\HandlerStack::create([
new \GuzzleHttp\Middleware::tap(function ($request) {
\Log::debug('EPREL Request:', ['url' => (string) $request->getUri()]);
}),
]),
]));
json_last_error() to debug malformed responses:
$response = $client->search()->execute();
if (json_last_error() !== JSON_ERROR_NONE) {
throw new \RuntimeException('Invalid JSON response');
}
Custom HTTP Client: Override the default Guzzle client for features like:
Accept: application/vnd.eprel.v1+json).Add Endpoints: Extend the client to support unsupported EPREL endpoints:
class CustomEprelClient extends EprelClient {
public function getProductDocuments(string $productId): array {
return $this->request('GET', "/products/{$productId}/documents");
}
}
Mocking for Tests:
Use Laravel’s MockHttp or a custom PSR-18 client:
$mockHandler = \Mockery::mock();
$mockHandler->shouldReceive('send')
->andReturn(new \GuzzleHttp\Psr7\Response(200, [], '{"data": []}'));
$client = new EprelClient(httpClient: new \GuzzleHttp\Client([
'handler' => new \GuzzleHttp\HandlerStack($mockHandler),
]));
Webhook Integration:
Poll for updates using ->search()->byLastUpdatedAfter($timestamp) and trigger webhooks on changes.
How can I help you explore Laravel packages today?