HTTP-Client for Germania's Fabrics API

4.0.1 2022-04-08 08:58 UTC

This package is auto-updated.

Last update: 2022-09-08 10:01:43 UTC



Germania KG · FabricsAPI client


composer require germania-kg/fabricsapi-client "^4.0"


The FabricsApiClient requures a Guzzle client with configured API base URL at hand:

use Germania\FabricsApiClient\FabricsApiClient;

$guzzle = new \GuzzleHttp\Client([
  // Note the trailing slash!
  'base_uri' => "https://path/to/api/"

$reader = new FabricsApiClient($guzzle);

Cache results

For better performance, a PSR-6 CacheItemPool may be used to cache the results. The CacheFabricsApiClient wraps the above FabricsApiClient:

use Germania\FabricsApiClient\CacheFabricsApiClient;

$api_reader = new FabricsApiClient($guzzle);
$psr6 = ...;
$lifetime = 86400;

$reader = new CacheFabricsApiClient($api_reader, $psr6, $lifetime);


Read all fabrics

// iterable
$all_fabrics = $reader->collection("anyCollection");

// Sort by pattern
$all_fabrics = $reader->collection("anyCollection", null, "pattern");

Search fabrics

// iterable
$matching_fabrics = $reader->collection("anyCollection", "seaflower");

// Sort by pattern
$matching_fabrics = $reader->collection("anyCollection", "seaflower", "pattern");

Read single fabric

// Germania\Fabrics\FabricInterface
$single = reader->fabric("anyCollection", "1-2345");

Unit tests

Copy phpunit.xml.dist to phpunit.xml and adapt to your needs. Obtain Germania's Fabrics API URL and the collection slug, otherwise the Unit Tests will fail and ask a wrong API…

  <env name="FABRICS_API" value="" />
  <env name="FABRICS_SLUG" value="duette" />
  <env name="FABRIC_NUMBER" value="1-2345" />

Run PhpUnit test or composer scripts like this:

$ composer test
# or
$ vendor/bin/phpunit