PHPackages                             ay4t/php-rest-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. ay4t/php-rest-client

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

ay4t/php-rest-client
====================

Multipurpose PHP rest client for consuming RESTful web services.

1.0.2(1y ago)3181MITPHP

Since Oct 28Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/ay4t/php-rest-client)[ Packagist](https://packagist.org/packages/ay4t/php-rest-client)[ Docs](https://github.com/ay4t/php-rest-client)[ RSS](/packages/ay4t-php-rest-client/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (4)Used By (1)

PHP REST Client
===============

[](#php-rest-client)

A flexible and robust PHP REST Client with advanced features for handling API requests.

Features
--------

[](#features)

- 🚀 Simple and intuitive API
- 🔄 Automatic retry mechanism for failed requests
- 📝 Comprehensive logging system
- ⚡ Custom exception handling
- 🔒 Configurable request options
- 🛠 Extensible architecture

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

[](#installation)

Install via Composer:

```
composer require ay4t/php-rest-client
```

Basic Usage
-----------

[](#basic-usage)

### Using Config Object (Recommended)

[](#using-config-object-recommended)

```
use Ay4t\RestClient\Client;
use Ay4t\RestClient\Config\Config;

// Initialize config
$config = new Config();
$config->setBaseUri('https://api.example.com')
       ->setApiKey('your-api-key-here');

$client = new Client($config);

// Make a GET request
try {
    $response = $client->cmd('GET', 'users');
    print_r($response);
} catch (Ay4t\RestClient\Exceptions\ApiException $e) {
    echo "Error: " . $e->getMessage();
    echo "HTTP Status: " . $e->getHttpStatusCode();
    echo "Response Body: " . $e->getResponseBody();
}
```

### Using Array Configuration (Alternative)

[](#using-array-configuration-alternative)

```
use Ay4t\RestClient\Client;

// Initialize with array config
$config = [
    'base_uri' => 'https://api.example.com',
    'headers' => [
        'Authorization' => 'Bearer your-api-key-here'
    ]
];

$client = new Client($config);
```

Advanced Features
-----------------

[](#advanced-features)

### Custom Logging

[](#custom-logging)

```
use Ay4t\RestClient\Logger\DefaultLogger;
use Ay4t\RestClient\Config\Config;

// Setup configuration
$config = new Config();
$config->setBaseUri('https://api.example.com')
       ->setApiKey('your-api-key-here');

// Custom log file location
$logger = new DefaultLogger('/path/to/custom.log');
$client = new Client($config, $logger);

// Logs will include:
// - Request details (method, URL, options)
// - Response status and body
// - Any errors that occur
```

### Retry Mechanism

[](#retry-mechanism)

```
// Configure retry settings
$client->setMaxRetries(5)      // Maximum number of retry attempts
       ->setRetryDelay(2000);  // Delay between retries in milliseconds

// The client will automatically:
// - Retry failed requests (except 4xx errors)
// - Wait between attempts
// - Throw ApiException after all retries fail
```

### Request Options

[](#request-options)

```
// Set global request options
$client->setRequestOptions([
    'timeout' => 30,
    'verify' => false,  // Disable SSL verification
    'headers' => [
        'User-Agent' => 'My Custom User Agent'
    ]
]);
```

### Error Handling

[](#error-handling)

```
use Ay4t\RestClient\Exceptions\ApiException;

try {
    $response = $client->cmd('POST', 'users', [
        'name' => 'John Doe',
        'email' => 'john@example.com'
    ]);
} catch (ApiException $e) {
    // Get detailed error information
    $statusCode = $e->getHttpStatusCode();
    $responseBody = $e->getResponseBody();
    $message = $e->getMessage();

    // Handle different status codes
    switch ($statusCode) {
        case 404:
            echo "Resource not found";
            break;
        case 401:
            echo "Unauthorized access";
            break;
        default:
            echo "An error occurred: $message";
    }
}
```

Implementing Custom Logger
--------------------------

[](#implementing-custom-logger)

You can implement your own logger by implementing the `LoggerInterface`:

```
use Ay4t\RestClient\Interfaces\LoggerInterface;

class MyCustomLogger implements LoggerInterface
{
    public function logRequest(string $method, string $url, array $options): void
    {
        // Your custom request logging logic
    }

    public function logResponse(int $statusCode, string $body): void
    {
        // Your custom response logging logic
    }

    public function logError(\Throwable $exception): void
    {
        // Your custom error logging logic
    }
}

// Use your custom logger
$client = new Client($config, new MyCustomLogger());
```

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

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

License
-------

[](#license)

This project is licensed under the MIT License - see the LICENSE file for details.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance59

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

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

Total

3

Last Release

384d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/831d350ec997ddc3e9d8958a40ec26668688d9120b9a4be362b5f5aa822e264f?d=identicon)[ay4t](/maintainers/ay4t)

---

Top Contributors

[![ay4t](https://avatars.githubusercontent.com/u/87152520?v=4)](https://github.com/ay4t "ay4t (9 commits)")

---

Tags

apiapi-clientapi-integrationapi-wrapperflexible-configurationhttp-clienthttp-requestsphpphp-libraryphp-rest-apirestrestfulweb-servicesclientresthttp client

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ay4t-php-rest-client/health.svg)

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

###  Alternatives

[eightpoints/guzzle-bundle

Integrates Guzzle 6.x, a PHP HTTP Client, into Symfony. Comes with easy and powerful configuration options and optional plugins.

45912.1M55](/packages/eightpoints-guzzle-bundle)[slimpay/hapiclient

An HTTP Client using HAL as the format for resources.

14317.3k](/packages/slimpay-hapiclient)[e-moe/guzzle6-bundle

Integrates Guzzle 6 into your Symfony application

11259.2k](/packages/e-moe-guzzle6-bundle)[opgg/riotquest

RiotQuest, PHP RiotAPI client library that focused on multi request from OP.GG

172.6k](/packages/opgg-riotquest)

PHPackages © 2026

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