PHPackages                             diegomel/client-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. diegomel/client-consumer

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

diegomel/client-consumer
========================

Apigility Client API Service Consumer

2.2(7y ago)06MITPHPPHP ^7.1

Since Oct 2Pushed 3y ago1 watchersCompare

[ Source](https://github.com/diegomel/ApigilityConsumer)[ Packagist](https://packagist.org/packages/diegomel/client-consumer)[ Docs](https://github.com/samsonasik/ApigilityConsumer)[ RSS](/packages/diegomel-client-consumer/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (8)Versions (42)Used By (0)

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

[](#apigilityconsumer)

[![Latest Version](https://camo.githubusercontent.com/2df790b5cc51b57b51ef817576d2ce2c434f7bd18fb5aea6089a042c954684b0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f646965676f6d656c2f41706967696c697479436f6e73756d65722e7376673f7374796c653d666c61742d737175617265)](https://github.com/samsonasik/ApigilityConsumer/releases)[![Build Status](https://camo.githubusercontent.com/4db1797799a397a993b8f31cd337d8fe5c25d0b1f5bef4c25bd19ddc3f8424f4/68747470733a2f2f7472617669732d63692e6f72672f73616d736f6e6173696b2f41706967696c697479436f6e73756d65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/samsonasik/ApigilityConsumer)[![Coverage Status](https://camo.githubusercontent.com/431a8953a07ccc09d941e8bc8219febd0ebc576dad91276e2e3e91e4e5026506/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f73616d736f6e6173696b2f41706967696c697479436f6e73756d65722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/samsonasik/ApigilityConsumer?branch=master)[![PHPStan](https://camo.githubusercontent.com/441b5874ce4df0a2defc892979c96c46889b69cb32119d04f0b48626349f8bc9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d656e61626c65642d627269676874677265656e2e7376673f7374796c653d666c6174)](https://github.com/phpstan/phpstan)[![Downloads](https://camo.githubusercontent.com/b49a105de675ad0c84fe4b8cf33e6c250b56acb828a8fa7e4ad4cddf128f38d9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646965676f6d656c2f636c69656e742d636f6e73756d65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/diegomel/client-consumer)

ZF Apigility Client module to consume API Services.

> This is README for version ^2.0 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 Zend\Http\Client as HttpClient;

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

        // 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 Zend\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 Zend\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

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 93.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 ~16 days

Total

41

Last Release

2850d ago

Major Versions

0.0.12 → 1.0.02016-10-07

1.4.0 → 2.0.02017-04-23

1.4.2 → 2.0.22017-08-20

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

2.0.0PHP ^7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/dd5b22efac0555c0d7d2367ab35677baf1f8e2b70ff7fc84bd4f2960e461506a?d=identicon)[diegomel](/maintainers/diegomel)

---

Top Contributors

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

---

Tags

httpclientoauthzf2consumerexpressivezf3apigility

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/diegomel-client-consumer/health.svg)

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

###  Alternatives

[samsonasik/apigility-consumer

Laminas API Tools Client API Service Consumer

151.6k](/packages/samsonasik-apigility-consumer)[swoole/etcd-client

Grpc PHP Client base on Swoole Http2 Coroutine

1973.2k1](/packages/swoole-etcd-client)

PHPackages © 2026

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