PHPackages                             behamin/service-proxy - 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. behamin/service-proxy

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

behamin/service-proxy
=====================

for proxy or sending requests to other services with useful utilities

v3.10.0(2y ago)102.2k5MITPHPPHP ^7.4 || ^8.0

Since Nov 5Pushed 1y ago3 watchersCompare

[ Source](https://github.com/behaminplus/behamin-proxy)[ Packagist](https://packagist.org/packages/behamin/service-proxy)[ RSS](/packages/behamin-service-proxy/feed)WikiDiscussions main Synced 6d ago

READMEChangelog (10)Dependencies (4)Versions (54)Used By (0)

Service Proxy
=============

[](#service-proxy)

Internal communication between services with useful tools
Make request by laravel http client

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

[](#installation)

```
composer require behamin/service-proxy
```

### Publish config

[](#publish-config)

```
php artisan vendor:publish --provider="Behamin\ServiceProxy\Providers\ProxyServiceProvider" --tag config
```

### Add services

[](#add-services)

Add your project's base url and global headers in `proxy.php` config

```
return [
    /**
     * Headers added to every request
     */
    'global_headers' => [
        'Accept' => 'application/json',
        ...
    ],

    'base_url' => env('PROXY_BASE_URL', env('APP_URL')),
];
```

Usage
-----

[](#usage)

### Normal usage

[](#normal-usage)

```
use Behamin\ServiceProxy\Proxy;

// Http Get
Proxy::withToken('Your bearer token')
    ->acceptJson()
    ->retry(3)
    ->withHeaders([
        "Content-Type" => "application\json"
    ])->get('api/articles');

Proxy::post('api/articles', [
    "title" => "Test title",
    "body" => "Test body"
]);

Proxy::patch('api/articles/1', [
    "title" => "Test title",
    "body" => "Test body"
]);

Proxy::put('api/articles', [
    "title" => "Test title",
    "body" => "Test body"
]);

Proxy::delete('api/articles/1');
```

### Using http request

[](#using-http-request)

```
use Behamin\ServiceProxy\Proxy;
use Illuminate\Http\Request;

public function index(Request $request) {
    $serviceName = 'test-service';
    Proxy::request($request, $serviceName);
}
```

### Proxy events

[](#proxy-events)

#### On success

[](#on-success)

```
use Behamin\ServiceProxy\Proxy;
use Behamin\ServiceProxy\Responses\ProxyResponse;

Proxy::get('api/articles/1')->onSuccess(function (ProxyResponse $proxyResponse) {
        $data = $proxyResponse->data();
        $message = $proxyResponse->message();
        $response = $proxyResponse->response();
        $items = $proxyResponse->items();
        $count = $proxyResponse->count();
        ...
    });
```

#### On error

[](#on-error)

```
use Behamin\ServiceProxy\Proxy;
use Behamin\ServiceProxy\Exceptions\ProxyException;

Proxy::get('api/articles/1')->onSuccess(function (ProxyException $proxyException) {
        $proxyResponse = $proxyException->proxyResponse;
        $trace = $proxyException->getTraceAsString();
        ...
    });
```

#### On data success

[](#on-data-success)

```
use Behamin\ServiceProxy\Proxy;

Proxy::get('api/articles/1')->onDataSuccess(function (array $data) {
        $id = $data['id'];
    });
```

#### On data collection success

[](#on-data-collection-success)

```
use Behamin\ServiceProxy\Proxy;

Proxy::get('api/articles/1')->onCollectionSuccess(function (array $items, int $count) {
        ...
    });
```

### Proxy response methods

[](#proxy-response-methods)

```
use Behamin\ServiceProxy\Proxy;

$proxyResponse = Proxy::get('api/articles/1');
```

MethodDescriptiondata()given dataitems()give itemscount()given items counterrors()given errors if there ismessage()given messageonSuccess($closure)When http request is successfulonError($closure)When http request is with erroronCollectionSuccess($closure)Get collection when http request is successfulonDataSuccess($closure)Get data when http request is successfulthrow()Throw error if http request failedtoException()Get exception if http request failed### Proxy request methods

[](#proxy-request-methods)

MethodReturn Typefake($callback = null)\\Illuminate\\Http\\Client\\Factoryaccept(string $contentType)\\Behamin\\ServiceProxy\\HttpacceptJson()\\Behamin\\ServiceProxy\\HttpasForm()\\Behamin\\ServiceProxy\\HttpasJson()\\Behamin\\ServiceProxy\\HttpasMultipart()\\Behamin\\ServiceProxy\\Httpasync()\\Behamin\\ServiceProxy\\Httpattach(string array $name, string $contents = '', string null $filename = null, array $headers = \[\])\\Behamin\\ServiceProxy\\HttpbaseUrl(string $url)\\Behamin\\ServiceProxy\\HttpbeforeSending(callable $callback)\\Behamin\\ServiceProxy\\HttpbodyFormat(string $format)\\Behamin\\ServiceProxy\\HttpcontentType(string $contentType)\\Behamin\\ServiceProxy\\Httpdd()\\Behamin\\ServiceProxy\\Httpdump()\\Behamin\\ServiceProxy\\Httpretry(int $times, int $sleep = 0)\\Behamin\\ServiceProxy\\Httpsink(stringresource $to)stub(callable $callback)\\Behamin\\ServiceProxy\\Httptimeout(int $seconds)\\Behamin\\ServiceProxy\\HttpwithBasicAuth(string $username, string $password)\\Behamin\\ServiceProxy\\HttpwithBody(resourcestring $content, string $contentType)withCookies(array $cookies, string $domain)\\Behamin\\ServiceProxy\\HttpwithDigestAuth(string $username, string $password)\\Behamin\\ServiceProxy\\HttpwithHeaders(array $headers)\\Behamin\\ServiceProxy\\HttpwithMiddleware(callable $middleware)\\Behamin\\ServiceProxy\\HttpwithOptions(array $options)\\Behamin\\ServiceProxy\\HttpwithToken(string $token, string $type = 'Bearer')\\Behamin\\ServiceProxy\\HttpwithUserAgent(string $userAgent)\\Behamin\\ServiceProxy\\HttpwithoutRedirecting()\\Behamin\\ServiceProxy\\HttpwithoutVerifying()\\Behamin\\ServiceProxy\\Httppool(callable $callback)arrayrequest(Request $request, string $service)\\Behamin\\ServiceProxy\\Responses\\ProxyResponseget(string $url, arraystringdelete(string $url, array $data = \[\])\\Behamin\\ServiceProxy\\Responses\\ProxyResponsehead(string $url, arraystringpatch(string $url, array $data = \[\])\\Behamin\\ServiceProxy\\Responses\\ProxyResponsepost(string $url, array $data = \[\])\\Behamin\\ServiceProxy\\Responses\\ProxyResponseput(string $url, array $data = \[\])\\Behamin\\ServiceProxy\\Responses\\ProxyResponsesend(string $method, string $url, array $options = \[\])\\Behamin\\ServiceProxy\\Responses\\ProxyResponsefakeSequence(string $urlPattern = '\*')\\Illuminate\\Http\\Client\\ResponseSequenceassertSent(callable $callback)voidassertNotSent(callable $callback)voidassertNothingSent()voidassertSentCount(int $count)voidassertSequencesAreEmpty()void### Mocking proxy response

[](#mocking-proxy-response)

You can use `mock()` on Proxy class before calling http methods and pass the json path in your 'tests/mock' directory, to mock a json for faking your Proxy response in test mode. Example:

```
use Behamin\ServiceProxy\Proxy;
Proxy::mock('response.json')->get('address');
```

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 53.8% 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 ~25 days

Recently: every ~99 days

Total

53

Last Release

680d ago

Major Versions

v1.5 → v2.02021-04-05

v2.2.4 → v3.02021-11-14

PHP version history (5 changes)v1.0PHP ^7.3

v2.0.1PHP ^7.3|^8.0

v2.2PHP ^7.4|^8.0

v3.8.0PHP ^7.4 || ^8.0

v3.9.4PHP ^7.4 || ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/75c05a67e6f24580b5b5421cc09fef166a6d290ba79bb8efc8bbe78fd5cbe8f7?d=identicon)[hebrahimzadeh](/maintainers/hebrahimzadeh)

![](https://www.gravatar.com/avatar/3ee1cdf1958a1862e71950b30d67116c57aa2f351f0defb75a17a5c761dfe2fc?d=identicon)[behamin-admin](/maintainers/behamin-admin)

---

Top Contributors

[![Hebrahimzadeh](https://avatars.githubusercontent.com/u/38420287?v=4)](https://github.com/Hebrahimzadeh "Hebrahimzadeh (113 commits)")[![omalizadeh](https://avatars.githubusercontent.com/u/12392549?v=4)](https://github.com/omalizadeh "omalizadeh (43 commits)")[![mhabedini](https://avatars.githubusercontent.com/u/13943537?v=4)](https://github.com/mhabedini "mhabedini (38 commits)")[![mdoulabi1](https://avatars.githubusercontent.com/u/59202978?v=4)](https://github.com/mdoulabi1 "mdoulabi1 (7 commits)")[![alirezabahram7](https://avatars.githubusercontent.com/u/46995989?v=4)](https://github.com/alirezabahram7 "alirezabahram7 (4 commits)")[![mahmooddelta](https://avatars.githubusercontent.com/u/30744647?v=4)](https://github.com/mahmooddelta "mahmooddelta (3 commits)")[![behamin-admin](https://avatars.githubusercontent.com/u/94783131?v=4)](https://github.com/behamin-admin "behamin-admin (1 commits)")[![promisedlandse](https://avatars.githubusercontent.com/u/74137203?v=4)](https://github.com/promisedlandse "promisedlandse (1 commits)")

---

Tags

laravelproxyhttprequestlaravelproxyGuzzleservicebehamin

### Embed Badge

![Health badge](/badges/behamin-service-proxy/health.svg)

```
[![Health](https://phpackages.com/badges/behamin-service-proxy/health.svg)](https://phpackages.com/packages/behamin-service-proxy)
```

###  Alternatives

[kozz/laravel-guzzle-provider

Guzzle 5/6 Service Provider for Laravel

621.1M2](/packages/kozz-laravel-guzzle-provider)[remic/guzzlecache

Laravel 5 package for caching Guzzle's GET requests.

189.3k](/packages/remic-guzzlecache)

PHPackages © 2026

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