PHPackages                             samsonasik/apigility-consumer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. samsonasik/apigility-consumer

ActiveLibrary[HTTP &amp; Networking](/categories/http)

samsonasik/apigility-consumer
=============================

Laminas API Tools Client API Service Consumer

4.0.1(4y ago)151.6k—0%2MITPHPPHP ^8.0CI passing

Since Oct 2Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/samsonasik/ApigilityConsumer)[ Packagist](https://packagist.org/packages/samsonasik/apigility-consumer)[ Docs](https://github.com/samsonasik/ApigilityConsumer)[ Fund](https://samsonasik.wordpress.com/donate/)[ RSS](/packages/samsonasik-apigility-consumer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (10)Versions (51)Used By (0)

ApigilityConsumer
=================

[](#apigilityconsumer)

[![Latest Version](https://camo.githubusercontent.com/81d60f926f14649c682579fce19611ea6603707eb036c02e15c0db7e9d25962f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f73616d736f6e6173696b2f41706967696c697479436f6e73756d65722e7376673f7374796c653d666c61742d737175617265)](https://github.com/samsonasik/ApigilityConsumer/releases)[![ci build](https://github.com/samsonasik/ApigilityConsumer/workflows/ci%20build/badge.svg)](https://github.com/samsonasik/ApigilityConsumer/workflows/ci%20build/badge.svg)[![Code Coverage](https://camo.githubusercontent.com/7a6b33a10b1138aff8d1d6163ed20b024351a0474875c04229ed9e77153aaa54/68747470733a2f2f636f6465636f762e696f2f67682f73616d736f6e6173696b2f41706967696c697479436f6e73756d65722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/samsonasik/ApigilityConsumer)[![PHPStan](https://camo.githubusercontent.com/441b5874ce4df0a2defc892979c96c46889b69cb32119d04f0b48626349f8bc9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d656e61626c65642d627269676874677265656e2e7376673f7374796c653d666c6174)](https://github.com/phpstan/phpstan)[![Downloads](https://camo.githubusercontent.com/db8acaee5db273d9b8582a968daf4cabb4c147dce839de1d2cca6744635cb386/68747470733a2f2f706f7365722e707567782e6f72672f73616d736f6e6173696b2f61706967696c6974792d636f6e73756d65722f646f776e6c6f616473)](https://packagist.org/packages/samsonasik/apigility-consumer)

Laminas API Tools Client module to consume API Services.

> This is README for version ^4.0 which only support php ^8.0 with laminas-servicemanager v3 and laminas-json v3.

> For version ^3.0 you can read at [version 3 readme](https://github.com/samsonasik/ApigilityConsumer/tree/3.x.x) which only support php ^7.1 with laminas-servicemanager v3 and laminas-json v3.

> For version ^2.0, you can read at [version 2 readme](https://github.com/samsonasik/ApigilityConsumer/tree/2.x.x) which only support php ^7.1 with zend-servicemanager v3 and zend-json v3.

> For version 1, you can read at [version 1 readme](https://github.com/samsonasik/ApigilityConsumer/tree/1.x.x) which still support php ^5.6|^7.0 with zend-servicemanager v2.

> Consider upgrading :)

Installation
------------

[](#installation)

Installation of this module uses [composer](https://getcomposer.org/).

```
composer require samsonasik/apigility-consumer
```

For its configuration, copy `vendor/samsonasik/apigility-consumer/config/apigility-consumer.local.php.dist` to `config/autoload/apigility-consumer.local.php` and configure with your api host url (required), oauth, and/or http auth settings:

```
use Laminas\Http\Client as HttpClient;

return [
    'apigility-consumer' => [
        'api-host-url' => 'http://api.host.com',

        // null for default or array of configuration listed at https://docs.zendframework.com/zend-http/client/intro/#configuration
        'http_client_options' => null,

        // for oauth
        'oauth' => [

            //default selected client
            'grant_type'    => 'password', // or client_credentials
            'client_id'     => 'foo',
            'client_secret' => 'foo_s3cret',

            // multiple clients to be selected
            'clients' => [
                'foo' => [ // foo is client_id
                    'grant_type'    => 'password', // or client_credentials
                    'client_secret' => 'foo_s3cret',
                ],
                'bar' => [ // bar is client_id
                    'grant_type'    => 'password', // or client_credentials
                    'client_secret' => 'bar_s3cret',
                ],
            ],

        ],

        // for basic and or digest
        'auth' => [

            // default client
            HttpClient::AUTH_BASIC => [
                'username' => 'foo',
                'password' => 'foo_s3cret'
            ],

            HttpClient::AUTH_DIGEST => [
                'username' => 'foo',
                'password' => 'foo_s3cret'
            ],

            // multiple clients to be selected
            'clients' => [
                'foo' => [ // foo is key represent just like "client_id" to ease switch per-client config
                    HttpClient::AUTH_BASIC => [
                        'username' => 'foo',
                        'password' => 'foo_s3cret'
                    ],

                    HttpClient::AUTH_DIGEST => [
                        'username' => 'foo',
                        'password' => 'foo_s3cret'
                    ],
                ],
                'bar' => [ // bar is key represent just like "client_id" to ease switch per-client config
                    HttpClient::AUTH_BASIC => [
                        'username' => 'bar',
                        'password' => 'bar_s3cret'
                    ],

                    HttpClient::AUTH_DIGEST => [
                        'username' => 'bar',
                        'password' => 'bar_s3cret'
                    ],
                ],
            ],

        ],
    ],
];
```

Then, enable it :

```
// config/modules.config.php
return [
    'ApigilityConsumer', // get(ClientAuthService::class);

$data = [
    'api-route-segment' => '/oauth',
    'form-request-method' => 'POST',

    'form-data' => [
        'username' => 'foo', // not required if grant_type config = 'client_credentials'
        'password' => '123', // not required if grant_type config = 'client_credentials'
    ],
];
$timeout  = 100;
$clientResult = $client->callAPI($data, $timeout);
```

**Specify Oauth "client\_id"**

You can specify what client\_id to be used on Http Auth with provide `withClient()`:

```
$clientResult = $client->withClient('bar') // bar is "client_id" defined in clients in oauth config
                       ->callAPI($data, $timeout);
```

**Reset Oauth "client\_id"**

We can re-use the client service and use back default "client\_id" with `resetClient()`:

```
$clientResult = $client->withClient('bar') // bar is "client_id" defined in clients in auth config
                       ->callAPI($data, $timeout);

$clientResultDefault = $client->resetClient()
                              ->callAPI($data, $timeout);
```

**2. ApigilityConsumer\\Service\\ClientService**

For general Api Call, with usage:

**a. General RAW Json data**

```
use ApigilityConsumer\Service\ClientService;

$data = [
    'api-route-segment' => '/api',
    'form-request-method' => 'POST',

    'form-data' => [
        // fields that will be used as raw json to be sent
        'foo' => 'fooValue',
    ],

    // token type and access token if required
    'token_type' =>  'token type if required, for example: "Bearer"',
    'access_token' => 'access token if required',
];

$client = $serviceManager->get(ClientService::class);

$timeout  = 100;
$clientResult = $client->callAPI($data, $timeout);
```

**b. With Upload file**

You can also do upload with it to upload file to API Service. For example:

```
use ApigilityConsumer\Service\ClientService;

$data['api-route-segment']   = '/api';
$data['form-request-method'] = 'POST';

$data['form-data']           = $request->getPost()->toArray();
$data['form-data']['files']  = $request->getFiles()->toArray();

/** data['form-data'] should be containst like the following
[
    'regular_key1' => 'regular_keyValue1',
    'regular_key2' => 'regular_keyValue2',

    'files' => [
        'file1' => [
            'type' => 'text/csv',
            'name' => 'file.csv',
            'tmp_name' => '/path/to/tmp/file',
            'error' => 'UPLOAD_ERR_OK',
            'size' => 123,
        ],
        'file2' => [
            'type' => 'text/csv',
            'name' => 'file2.csv',
            'tmp_name' => '/path/to/tmp/file2',
            'error' => 'UPLOAD_ERR_OK',
            'size' => 123,
        ],
    ],
]
*/

$client = $serviceManager->get(ClientService::class);

$timeout  = 100;
$clientResult = $client->callAPI($data, $timeout);
```

**With include Http (basic or digest) Authentication**

if api call require authentication for basic or digest, you can apply `->withHttpAuthType()`:

```
use Laminas\Http\Client as HttpClient;

$clientResult = $client->withHttpAuthType(HttpClient::AUTH_BASIC)
                       ->callAPI($data, $timeout);
// OR
$clientResult = $client->withHttpAuthType(HttpClient::AUTH_DIGEST)
                       ->callAPI($data, $timeout);
```

that will read of specified basic or digest auth config we defined at `config/autoload/apigility-consumer.local.php`.

If you want to specify custom username and password for the Http Auth on `callAPI()` call, you can specify via `$data`:

```
use Laminas\Http\Client as HttpClient;

$data = [
    'api-route-segment' => '/api',
    'form-request-method' => 'POST',

    'form-data' => [
        // fields that will be used as raw json to be sent
        'foo' => 'fooValue',
    ],

    'auth' => [
        HttpClient::AUTH_BASIC => [
            'username' => 'foo',
            'password' => 'foo_s3cret'
        ],

        HttpClient::AUTH_DIGEST => [
            'username' => 'foo',
            'password' => 'foo_s3cret'
        ],
    ],
];

$clientResult = $client->withHttpAuthType(HttpClient::AUTH_BASIC)
                       ->callAPI($data, $timeout);
// OR
$clientResult = $client->withHttpAuthType(HttpClient::AUTH_DIGEST)
                       ->callAPI($data, $timeout);
```

**Specify "client\_id" on Http Auth**

On Http Auth, there is no "client\_id" definition concept. On `ClientService`, they are keys that represent just like "client\_id" to ease switch client specific http auth.

To allow You can specify what "client\_id" to be used on Http Auth with provide `withClient()`:

```
$clientResult = $client->withClient('bar') // bar is "client_id" defined in clients in auth config
                       ->withHttpAuthType(HttpClient::AUTH_BASIC)
                       ->callAPI($data, $timeout);
```

**Reset "client\_id" Http Auth**

We can re-use the client service and use back default "client\_id" with `resetClient()`:

```
$clientResult = $client->withClient('bar') // bar is "client_id" defined in clients in auth config
                       ->withHttpAuthType(HttpClient::AUTH_BASIC)
                       ->callAPI($data, $timeout);

$clientResultDefault = $client->resetClient()
                              ->callAPI($data, $timeout);
```

**Reset Http Auth Type**

After one or both `HttpClient::AUTH_BASIC` or `HttpClient::AUTH_DIGEST` used, we can re-use the client service and use back normal API Call without Http Authentication with apply `->resetHttpAuthType()`:

```
$clientResultWithBasicAuth   = $client->withHttpAuthType(HttpClient::AUTH_BASIC)
                                      ->callAPI($data1, $timeout);
$clientResultWithDigestAuth  = $client->withHttpAuthType(HttpClient::AUTH_DIGEST)
                                      ->callAPI($data2, $timeout);

// RESET IT TO NORMAL WITHOUT HTTP AUTHENTICATION
$clientResultWithoutHttpAuth = $client->resetHttpAuthType()
                                      ->callAPI($data3, $timeout);
```

Client Result of callAPI() returned usage
-----------------------------------------

[](#client-result-of-callapi-returned-usage)

The `$clientResult` will be a `ApigilityConsumer\Result\ClientResult` or `ApigilityConsumer\Result\ClientAuthResult` instance, with this instance, you can do:

```
//...
$clientResult = $client->callAPI($data, $timeout);

if (! $clientResult->success) {
    var_dump($clientResult::$messages);
} else {
    var_dump($clientResult->data);
}
```

Contributing
------------

[](#contributing)

Contributions are very welcome. Please read [CONTRIBUTING.md](https://github.com/samsonasik/ApigilityConsumer/blob/master/CONTRIBUTING.md)

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance58

Moderate activity, may be stable

Popularity26

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 99.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~40 days

Recently: every ~189 days

Total

50

Last Release

1554d ago

Major Versions

1.4.2 → 2.0.22017-08-20

1.4.3 → 2.1.72018-12-30

1.x-dev → 2.1.82019-12-01

2.x-dev → 3.0.02020-01-09

3.x-dev → 4.0.02021-06-20

PHP version history (3 changes)0.0.1PHP ^5.6|^7.0

2.0.0PHP ^7.1

4.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/19076b7688ca1c8ee79ab3ac6fa6acdd7b96012973aba3b1a06cbb3154d7f3e5?d=identicon)[samsonasik](/maintainers/samsonasik)

---

Top Contributors

[![samsonasik](https://avatars.githubusercontent.com/u/459648?v=4)](https://github.com/samsonasik "samsonasik (276 commits)")[![Perfect-Web](https://avatars.githubusercontent.com/u/1730020?v=4)](https://github.com/Perfect-Web "Perfect-Web (1 commits)")

---

Tags

apibasicdigestlaminaslaminas-apimezziooauthzf2zf3zf3-apigility-clienthttpapiclientlaminasoauthmezzioconsumerapigilitylaminas3laminas2

###  Code Quality

Static AnalysisPHPStan, Rector

Type Coverage Yes

### Embed Badge

![Health badge](/badges/samsonasik-apigility-consumer/health.svg)

```
[![Health](https://phpackages.com/badges/samsonasik-apigility-consumer/health.svg)](https://phpackages.com/packages/samsonasik-apigility-consumer)
```

###  Alternatives

[mezzio/mezzio-fastroute

FastRoute integration for Mezzio

162.7M52](/packages/mezzio-mezzio-fastroute)[mezzio/mezzio-tooling

Migration and development tooling for Mezzio

191.1M21](/packages/mezzio-mezzio-tooling)[mezzio/mezzio-problem-details

Problem Details for PSR-7 HTTP APIs addressing the RFC 7807 standard

271.1M24](/packages/mezzio-mezzio-problem-details)[mezzio/mezzio-authentication

Authentication middleware for Mezzio and PSR-7 applications

121.6M26](/packages/mezzio-mezzio-authentication)[jsor/hal-client

A lightweight client for consuming and manipulating Hypertext Application Language (HAL) resources.

2425.9k1](/packages/jsor-hal-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
