PHPackages                             paysera/lib-rest-client-common - 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. [API Development](/categories/api)
4. /
5. paysera/lib-rest-client-common

ActiveLibrary[API Development](/categories/api)

paysera/lib-rest-client-common
==============================

Base classes/helpers used in REST Clients

2.8.0(1mo ago)5220.1k↓35%11[4 PRs](https://github.com/paysera/lib-rest-client-common/pulls)5PHPPHP &gt;=7.4

Since Feb 27Pushed 1mo ago9 watchersCompare

[ Source](https://github.com/paysera/lib-rest-client-common)[ Packagist](https://packagist.org/packages/paysera/lib-rest-client-common)[ RSS](/packages/paysera-lib-rest-client-common/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (10)Versions (30)Used By (5)

lib-rest-client-common [![](https://camo.githubusercontent.com/8d622c0e3e9c48ecaab566fe7420d541c7172fc017e7a3eee1857b3f79905c7b/68747470733a2f2f7472617669732d63692e6f72672f706179736572612f6c69622d726573742d636c69656e742d636f6d6d6f6e2e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/8d622c0e3e9c48ecaab566fe7420d541c7172fc017e7a3eee1857b3f79905c7b/68747470733a2f2f7472617669732d63692e6f72672f706179736572612f6c69622d726573742d636c69656e742d636f6d6d6f6e2e7376673f6272616e63683d6d6173746572)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#lib-rest-client-common-)

Generic library for RESTful API clients

#### Usage

[](#usage)

You should create `ClientFactory` class, which extends `ClientFactoryAbstract`. In `ClientFactory` you can override any parent configuration if needed.

Simple example of `ClientFactory`:

```
class TestClientFactory extends ClientFactoryAbstract
{
    const DEFAULT_BASE_URL = 'http://example.com/test/rest/v1/{locale}/';

    private $apiClient;

    public function __construct(array $options)
    {
        $this->apiClient = $this->createApiClient($options);
    }

    public function getTestClient()
    {
        return new TestClient($this->apiClient);
    }
}
```

Using this pattern you can reuse same `ApiClient` with it's authentication and other options in different APIs.

In addition to `ClientFactory`, you should create also the `Client` itself. Finally you will use the `Client` itself, so it should contain all the methods your API provides.

Simple example of `TestClient`:

```
class TestClient
{
    private $apiClient;

    public function __construct(ApiClient $apiClient)
    {
        $this->apiClient = $apiClient;
    }

    public function withOptions(array $options)
    {
        return new TestClient($this->apiClient->withOptions($options));
    }

    /**
     * @return array
     */
    public function getSomething()
    {
        $request = $this->apiClient->createRequest(
            RequestMethodInterface::METHOD_GET,
            sprintf('/something'),
            null
        );
        return $this->apiClient->makeRequest($request);
    }
}
```

You should implement mapping or data transformation where applicable in `TestClient` methods.

#### Example:

[](#example)

```
use Paysera\Client\CategoryClient\ClientFactory;

$clientFactory = new ClientFactory([
    'base_url' => 'custom base url',
    'auth_base_url' => 'custom auth base url',
    'basic' => [
        'username' => 'user',
        'password' => 'pass'
    ],
    'oauth' => [
        'token' => [
            'access_token' => 'your oauth access token',
            'refresh_token' => 'your oauth refresh token',
        ],
    ],
    'mac' => [
        'mac_id' => 'mac id',
        'mac_secret' => 'mac secret',
        'parameters' => [
            // list of needed parameters
        ]
    ],
    'url_parameters' => [
        'locale' => 'en',
        // list of base_url placeholder parameter values
    ],
    'headers' => [
        'Accept-Language' => 'en',
    ],
    // other configuration options
]);

$testClient = $clientFactory->getTestClient();
$data = $testClient->getSomething();
```

- Please note that only single authentication mechanism is supported.

#### Middleware

[](#middleware)

You can add custom Guzzle middleware to client factories. Middleware must be a callable (e.g. a class with `__invoke`):

```
use Psr\Http\Message\RequestInterface;

class CustomMiddleware
{
    public function __invoke(callable $handler): callable
    {
        return function (RequestInterface $request, array $options) use ($handler) {
            $request = $request->withHeader('X-Custom-Header', 'value');
            return $handler($request, $options);
        };
    }
}
```

Register middleware on the factory:

```
$factory = new TestClientFactory([]);
$factory->addMiddleware(new CustomMiddleware());
$client = $factory->getTestClient();
```

Middleware can also be added after client creation (e.g., via Symfony DI `addMethodCall`). It is pushed onto the existing `HandlerStack` and takes effect on subsequent requests.

In case you want to change some configuration options at runtime, use `TestClient::withOptions()`:

```
$factory = new TestClientFactory([
    MacAuthentication::TYPE => [
        'mac_id' => $macId,
        'mac_secret' => $macSecret,
        'parameters' => [
            'user_id' => 100,
        ]
    ]
]);

$client = $factory->getTestClient();

$client2 = $factory->getTestClient()->withOptions([
    MacAuthentication::TYPE => [
        'parameters' => ['user_id' => 999],
    ]
]);
```

Here for `$client2` only `user_id` in `parameters` will be changed. Other configuration, like `mac_id`, `mac_secret` will be left intact.

###  Health Score

62

—

FairBetter than 99% of packages

Maintenance90

Actively maintained with recent releases

Popularity41

Moderate usage in the ecosystem

Community30

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor4

4 contributors hold 50%+ of commits

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 ~124 days

Recently: every ~277 days

Total

28

Last Release

46d ago

Major Versions

1.1.1 → 2.0.02018-07-19

PHP version history (2 changes)1.0.0PHP &gt;=5.5

2.7.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/9d385187c2b529d5c1189dfc3763972f76738d24293593ff3db876fff82321db?d=identicon)[paysera.com](/maintainers/paysera.com)

---

Top Contributors

[![siarhei-kruk](https://avatars.githubusercontent.com/u/274785579?v=4)](https://github.com/siarhei-kruk "siarhei-kruk (6 commits)")[![borilyordanov](https://avatars.githubusercontent.com/u/11679283?v=4)](https://github.com/borilyordanov "borilyordanov (4 commits)")[![vbartusevicius](https://avatars.githubusercontent.com/u/7325630?v=4)](https://github.com/vbartusevicius "vbartusevicius (3 commits)")[![mSprunskas](https://avatars.githubusercontent.com/u/4427922?v=4)](https://github.com/mSprunskas "mSprunskas (2 commits)")[![aliaksandr-lishko-paysera](https://avatars.githubusercontent.com/u/161292120?v=4)](https://github.com/aliaksandr-lishko-paysera "aliaksandr-lishko-paysera (2 commits)")[![aliaksandr-lishko](https://avatars.githubusercontent.com/u/161292120?v=4)](https://github.com/aliaksandr-lishko "aliaksandr-lishko (2 commits)")[![tomas7777](https://avatars.githubusercontent.com/u/9091359?v=4)](https://github.com/tomas7777 "tomas7777 (2 commits)")[![Laurgrin](https://avatars.githubusercontent.com/u/15212775?v=4)](https://github.com/Laurgrin "Laurgrin (1 commits)")[![ezgass](https://avatars.githubusercontent.com/u/3251505?v=4)](https://github.com/ezgass "ezgass (1 commits)")[![feraldrood](https://avatars.githubusercontent.com/u/7203522?v=4)](https://github.com/feraldrood "feraldrood (1 commits)")[![alexanderzaiets-paysera](https://avatars.githubusercontent.com/u/101864629?v=4)](https://github.com/alexanderzaiets-paysera "alexanderzaiets-paysera (1 commits)")[![mariusbalcytis](https://avatars.githubusercontent.com/u/1590072?v=4)](https://github.com/mariusbalcytis "mariusbalcytis (1 commits)")[![oleksandr-gribiennikov-paysera](https://avatars.githubusercontent.com/u/148878964?v=4)](https://github.com/oleksandr-gribiennikov-paysera "oleksandr-gribiennikov-paysera (1 commits)")

---

Tags

activebackendoss-librarypackagist

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/paysera-lib-rest-client-common/health.svg)

```
[![Health](https://phpackages.com/badges/paysera-lib-rest-client-common/health.svg)](https://phpackages.com/packages/paysera-lib-rest-client-common)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.9M737](/packages/sylius-sylius)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

273.0k](/packages/eslazarev-wildberries-sdk)[algolia/algoliasearch-client-php

API powering the features of Algolia.

69735.1M159](/packages/algolia-algoliasearch-client-php)[oat-sa/tao-core

TAO core extension

66143.7k122](/packages/oat-sa-tao-core)

PHPackages © 2026

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