PHPackages                             codecoz/laravel-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. codecoz/laravel-rest-client

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

codecoz/laravel-rest-client
===========================

A powerful, Laravel-friendly REST API client with authentication, logging, caching, and specific API wrappers.

v1.0.0(4mo ago)31MITPHPPHP ^8.3

Since Dec 27Pushed 4mo agoCompare

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

READMEChangelog (1)Dependencies (7)Versions (2)Used By (0)

CodeCoz Laravel REST Client
===========================

[](#codecoz-laravel-rest-client)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5aa6733d3ae6f93d433471c5a71c191e7bfad20e86dd881a1d09696cb2d85a06/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f6465636f7a2f6c61726176656c2d726573742d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/codecoz/laravel-rest-client)[![Total Downloads](https://camo.githubusercontent.com/e04017abd185cb019694d05da0d5e57ad7454ddb895b799d77205cd9b97a6ea1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f6465636f7a2f6c61726176656c2d726573742d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/codecoz/laravel-rest-client)[![License](https://camo.githubusercontent.com/4156f84ca4a52bcb408fac309676969ddba67a27f5f905736cb6b4e2807c4fd0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f636f6465636f7a2f6c61726176656c2d726573742d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://github.com/codecoz/laravel-api-client/blob/main/LICENSE)

A powerful, Laravel-native REST API client package built on top of **Illuminate\\Http\\Client**. It provides a clean, fluent syntax for consuming external RESTful APIs with enterprise-grade features:

- Authentication handling (Bearer token, API key)
- Comprehensive request/response logging
- Intelligent response caching
- Robust exception handling with specific exception classes
- Easy creation of specific API wrappers
- Fully configurable and extensible

**Website:**
**GitHub Repository:**

Features
--------

[](#features)

- Built exclusively on Laravel's native `Illuminate\Http\Client` (no direct Guzzle dependency)
- Global and per-request authentication (Bearer token, API key, custom headers)
- Automatic request/response logging via Laravel HTTP Client events
- Smart caching with global and per-call control
- Advanced exception handling (4xx, 5xx, connection errors)
- Fluent, chainable API with Laravel-style syntax
- Support for building tailored API wrappers
- Fully configurable via published config file
- PSR-4 compliant, follows SOLID and KISS principles
- Compatible with **Laravel 10, 11 and 12**

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

[](#installation)

Require the package via Composer:

```
composer require codecoz/laravel-rest-client
```

Publish Configuration
---------------------

[](#publish-configuration)

```
php artisan vendor:publish --provider="CodeCoz\Laravel\RestClient\RestClientServiceProvider" --tag="rest-client-config"
```

Configuration
-------------

[](#configuration)

After publishing, edit config/rest-client.php or use environment variables:

```
REST_CLIENT_BASE_URL=https://api.example.com
REST_CLIENT_LOGGING=true
REST_CLIENT_LOG_CHANNEL=stack
REST_CLIENT_LOG_SANITIZE=true
REST_CLIENT_LOG_PAYLOAD=true
REST_CLIENT_LOG_LEVEL=debug
REST_CLIENT_CACHING=false
REST_CLIENT_CACHE_STORE=file
REST_CLIENT_AUTH_TYPE=bearer
```

Key Configuration Options
-------------------------

[](#key-configuration-options)

```
return [
    'base_url' => env('REST_CLIENT_BASE_URL', 'https://api.example.com'),

    'default_auth' => [
        'type' => env('REST_CLIENT_AUTH_TYPE', 'bearer'),
        'header' => env('REST_CLIENT_AUTH_HEADER', 'Authorization'),
        'token' => env('REST_CLIENT_AUTH_TOKEN'),
        'param_key' => env('REST_CLIENT_API_KEY_PARAM', 'api_key'),
        'provider' => null  // \App\Services\MyTokenProvider::class
    ],

    'logging' => [
        'enabled' => env('REST_CLIENT_LOGGING', true),
        'sanitize'=> env('REST_CLIENT_LOG_SANITIZE', true),
        'payload' => env('REST_CLIENT_LOG_PAYLOAD', true),
        'channel' => env('REST_CLIENT_LOG_CHANNEL', 'stack'),
        'level'   => env('REST_CLIENT_LOG_LEVEL', 'debug'),
    ],

    'caching' => [
        'enabled' => env('REST_CLIENT_CACHING', false),
        'store' =>   env('REST_CLIENT_CACHE_STORE', 'file'),
        'ttl' =>     env('REST_CLIENT_CACHE_LIFETIME', 3600), // 1 hour default
    ],
];
```

Usage
-----

[](#usage)

### Basic HTTP Requests

[](#basic-http-requests)

```
use CodeCoz\Laravel\RestClient\Facades\RestClient;

// GET request
$response = RestClient::get('/posts');

// GET with query parameters
RestClient::get('/posts', ['page' => 2]);

// POST request
RestClient::post('/posts', ['title' => 'New Post', 'body' => '...']);

// Form data
RestClient::asForm()->post('/login', [
    'email' => 'user@example.com',
    'password' => 'secret'
]);

// Chain options
RestClient::cache(600)
          ->withoutLogging()
          ->get('/expensive-endpoint');
```

Authentication
--------------

[](#authentication)

### Global (via config):

[](#global-via-config)

```
// config/rest-client.php
'auth' => [
    'type' => 'bearer',
    'token' => 'your-global-token-here',
]
```

### Per-request override:

[](#per-request-override)

```
RestClient::withToken('temporary-token')->get('/protected-resource');
```

Logging
-------

[](#logging)

Logging is enabled by default and uses Laravel's log channels. Logs include URL, method, headers, and body. Disable for sensitive requests:

```
RestClient::withoutLogging()->post('/webhook', $payload);
```

Caching
-------

[](#caching)

### Enable globally in config or per request:

[](#enable-globally-in-config-or-per-request)

```
// Cache response for 10 minutes
RestClient::cache(600)->get('/slow-endpoint');

// Disable caching for a specific call
RestClient::withoutCache()->get('/real-time-data');
```

Exception Handling
------------------

[](#exception-handling)

The package throws meaningful exceptions:

```
use CodeCoz\Laravel\RestClient\Facades\RestClient;
use CodeCoz\Laravel\RestClient\Exceptions\{
    ClientErrorException,
    ServerErrorException,
    ConnectionException,
    RestClientException
};

try {
    $data = RestClient::get('/users/999')->json();
} catch (ClientErrorException $e) {
    // 4xx errors (401, 403, 404, 422, etc.)
    // Access API error details: $e->getResponseData()
    return response()->json(['error' => $e->getMessage()], $e->getCode());

} catch (ServerErrorException $e) {
    // 5xx errors
    \Log::error('External API error', ['exception' => $e]);

} catch (ConnectionException $e) {
    // Network / timeout / DNS issues
    return response()->json(['error' => 'Service unavailable'], 502);

} catch (RestClientException $e) {
    // Any other API-related error
}
```

Building Specific API Wrappers
------------------------------

[](#building-specific-api-wrappers)

### Create clean, reusable clients for any external API:

[](#create-clean-reusable-clients-for-any-external-api)

```
// app/Services/GitHubApiClient.php
namespace App\Services;

use CodeCoz\Laravel\RestClient\Facades\RestClient;

class GitHubApiClient
{
    public function __construct()
    {
        RestClient::withToken(config('services.github.token'))
                  ->baseUrl('https://api.github.com');
    }

    public function getUser(string $username)
    {
        return RestClient::cache(300)
                         ->get("/users/{$username}")
                         ->json();
    }

    public function getRepos(string $username)
    {
        return RestClient::get("/users/{$username}/repos")->json();
    }

    public function createIssue(string $owner, string $repo, array $data)
    {
        return RestClient::post("/repos/{$owner}/{$repo}/issues", $data)->json();
    }
}
```

### Usage:

[](#usage-1)

```
$github = new App\Services\GitHubApiClient();
$user = $github->getUser('torvalds');
```

Testing
-------

[](#testing)

The package includes unit tests using Orchestra Testbench. Run tests with:

```
composer test
```

Changelog
---------

[](#changelog)

Please see CHANGELOG.md for recent changes.

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

[](#contributing)

Contributions are welcome! Please follow the standard GitHub flow:

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Submit a pull request

Security
--------

[](#security)

If you discover any security-related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

CodeCoz Team All contributors

License
-------

[](#license)

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

```

This is the complete, production-ready `README.md` file for the `codecoz/laravel-rest-client` package, combining all previous features, code examples, and best practices into a single, well-structured Markdown document.

```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance75

Regular maintenance activity

Popularity5

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

135d ago

### Community

Maintainers

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

---

Tags

httpapiclientlaravelrest

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/codecoz-laravel-rest-client/health.svg)

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

###  Alternatives

[pusher/pusher-http-laravel

\[DEPRECATED\] A Pusher bridge for Laravel

400509.0k3](/packages/pusher-pusher-http-laravel)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[vinelab/http

An http library developed for the laravel framework. aliases itself as HttpClient

59300.2k11](/packages/vinelab-http)[laragear/api-manager

Manage multiple REST servers to make requests in few lines and fluently.

161.8k](/packages/laragear-api-manager)[rap2hpoutre/jacky

Opinionated REST JSON HTTP API client for laravel

174.4k](/packages/rap2hpoutre-jacky)

PHPackages © 2026

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