PHPackages                             adiafora/php-api-client - 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. adiafora/php-api-client

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

adiafora/php-api-client
=======================

Packet to send to an Api using PHP.

1.3.9(5y ago)196MITPHPPHP &gt;=7.2

Since Oct 18Pushed 5y ago1 watchersCompare

[ Source](https://github.com/adiafora/php-api-client)[ Packagist](https://packagist.org/packages/adiafora/php-api-client)[ RSS](/packages/adiafora-php-api-client/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (2)DependenciesVersions (14)Used By (0)

php-api-client
==============

[](#php-api-client)

This package makes it very easy to access any API using both GET and POST requests. You can also send headers and parameters.

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

[](#installation)

Run:

```
    composer require "adiafora/php-api-client"
```

Configurations
--------------

[](#configurations)

You can set parameters for curl using global constants.

`SET_CURLOPT_CONNECTTIMEOUT` - The number of seconds to wait while trying to connect. Use 0 to wait indefinitely. Default is 10. `SET_CURLOPT_TIMEOUT` - The maximum number of seconds to allow cURL functions to execute. Default is 10.

Usage
-----

[](#usage)

You must create a class that extends the `Adiafora\ApiClient\AbstractApiClient` abstract class. And define the methods:

`getHeaders()` - returns an array of headers.

`getUrl()` - returns a string, the API url.

And in your project, you must refer to this class, which extends the `Adiafora\ApiClient\AbstractApiClient`.

When accessing your class, you can pass the GET or POST request type (by default GET) and an array of request parameters, if any, to the constructor method. if you execute a GET request without parameters, you don't need to pass anything to the constructor method.

```
 //Example

 $api = new MyApiClient('POST', ['name' => 'Sergey']);
 // or
 $api = new MyApiClient();

```

To make a request to the API, call the `send()` method:

```
 $response = $api->send();
```

The method returns an object of class `Adiafora\ApiClient\ApiResponse` that contains these methods:

`code()` - return code of response.

`response()` - return response from the API decoded using json\_decode(). Because most APIs return a response in json format. If you want to get the answer as it is, then use the dirty() method.

`dirty()` - return the answer as it is without transformations.

`error()` - return curl\_error() for the curl.

`errno()` - return curl\_errno() for the curl.

`requestParameters()` - return parameters of request.

`requestUrl()` - return url of request.

`requestHeaders()` - return headers of request.

`totalTime()` - return total transaction time in seconds for last transfer.

Real example
------------

[](#real-example)

For example, we need to connect to the Yandex.Webmaster API.

> For more information, see the API documentation

We are creating a class `WebmasterApiClient`

```
    use Adiafora\ApiClient\AbstractApiClient;

    class WebmasterApiClient extends AbstractApiClient
    {
        private $resource;

        private $token;

        private $userId;

        public function __construct(string $resource, string $method, array $params = [])
        {
            parent::__construct($method, $params);

            $this->resource = $resource;
            $this->userId   = USER_ID;
            $this->token    = TOKEN;
        }

        public function getHeaders(): array
        {
            return [
                'Authorization: OAuth ' . $this->token,
                'Accept-Language: ru',
                'Content-Type: application/json; charset=utf-8'
            ];
        }

        public function getUrl(): string
        {
            return 'https://api.webmaster.yandex.net/v4/user/' . $this->userId . '/' . $this->resource;
        }
    }
```

We have implemented 2 required methods `getHeaders()` and `getUrl()`. Everything else, including the implementation of the constructor method, is only necessary for implementing a specific API.

Now we want to get a list of all hosts. There is nothing easier! Just:

```
// @see https://yandex.com/dev/webmaster/doc/dg/reference/hosts-docpage/
$api = new WebmasterApiClient('hosts', Adiafora\ApiClient\Method::GET);
$response = $api->send();

$response->code(); // 200
$response->response(); // array()
```

Or getting the history of SQI changes using the parameters:

```
// @see https://yandex.com/dev/webmaster/doc/dg/reference/sqi-history.html/
$api = new WebmasterApiClient('hosts/' . $hostId . '/sqi-history', Adiafora\ApiClient\Method::GET, [
            'date_from' => '2016-01-01T00:00:00,000+0300',
        ]);
$api->send();
```

License
-------

[](#license)

The MIT License (MIT). Please see License File for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~14 days

Recently: every ~7 days

Total

13

Last Release

1870d ago

### Community

Maintainers

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

---

Top Contributors

[![adiafora](https://avatars.githubusercontent.com/u/53189193?v=4)](https://github.com/adiafora "adiafora (22 commits)")

---

Tags

phpapihttp clientapi client

### Embed Badge

![Health badge](/badges/adiafora-php-api-client/health.svg)

```
[![Health](https://phpackages.com/badges/adiafora-php-api-client/health.svg)](https://phpackages.com/packages/adiafora-php-api-client)
```

###  Alternatives

[php-curl-class/php-curl-class

PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs.

3.3k9.5M353](/packages/php-curl-class-php-curl-class)[ismaeltoe/osms

PHP library wrapper of the Orange SMS API.

4540.0k](/packages/ismaeltoe-osms)[butschster/kraken-api-client

The most powerful and extendable REST API / Websocket client for Kraken.com. Built on PHP8.0

4914.3k](/packages/butschster-kraken-api-client)

PHPackages © 2026

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