PHPackages                             shetabit/extractor - 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. shetabit/extractor

ActiveLibrary[API Development](/categories/api)

shetabit/extractor
==================

a `micro client` generator to communicate between `micro services` in laravel apps

v4.0.0(3y ago)962005MITPHPPHP &gt;=7.2CI passing

Since Aug 3Pushed yesterday3 watchersCompare

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

READMEChangelog (10)Dependencies (6)Versions (14)Used By (0)

 [![](resources/images/microservices-communication.png?raw=true)](resources/images/microservices-communication.png?raw=true)

Laravel Extractor
=================

[](#laravel-extractor)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Latest Version on Packagist](https://camo.githubusercontent.com/12dc2f463a7d1aa7f9d7a984f8913783e7fb0831f10c54eed9346ff7c2af6590/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73686574616269742f657874726163746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/shetabit/extractor)[![Total Downloads on Packagist](https://camo.githubusercontent.com/82eee4037bbd76c6c29fde5ec34e9bf13dba5329751f807b5721d740f7f3d575/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73686574616269742f657874726163746f722e7376673f636f6c6f723d253233463138267374796c653d666c61742d737175617265)](https://packagist.org/packages/shetabit/extractor)[![Tests](https://camo.githubusercontent.com/80a85bebfba4363f7ab7768b835822d69b8619da86b56cc7760dc3d46de1ea54/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73686574616269742f657874726163746f722f74657374732e796d6c3f6272616e63683d6d6173746572266c6162656c3d5465737473267374796c653d666c61742d737175617265)](https://github.com/shetabit/extractor/actions/workflows/tests.yml)[![Code Style](https://camo.githubusercontent.com/77715e3ced3704703d7cb81d2c5d67bf3f1a1ba4fdf03b2ce9c2f2ed86ffbc47/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73686574616269742f657874726163746f722f636f64652d7374796c652e796d6c3f6272616e63683d6d6173746572266c6162656c3d436f64652532305374796c65267374796c653d666c61742d737175617265)](https://github.com/shetabit/extractor/actions/workflows/code-style.yml)[![Static Analysis](https://camo.githubusercontent.com/762c78fd6079ed4af5f5d08b118e3ccf4a6e3ec32e70af096008e195ce5ec7a4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73686574616269742f657874726163746f722f7374617469632d616e616c797369732e796d6c3f6272616e63683d6d6173746572266c6162656c3d537461746963253230416e616c79736973267374796c653d666c61742d737175617265)](https://github.com/shetabit/extractor/actions/workflows/static-analysis.yml)[![Code Coverage](https://camo.githubusercontent.com/11b704bb953fdaa89fbc3bbe7fad73c596ffc1d9f755bc3eca321a8a2c8c3e8d/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f73686574616269742f657874726163746f722f6d61737465723f6c6162656c3d436f766572616765267374796c653d666c61742d737175617265)](https://codecov.io/gh/shetabit/extractor)

Communicate with **remote servers** or **microservices** in an easy way.

All requests and responses can be **cached** and **manipulated** on runtime using **middlewares**.

This package requires `PHP 8.4+` and supports `Laravel 12+`.

[Donate me](https://yekpay.me/mahdikhanzadi) if you like this package 😎 ![:bowtie:](https://github.githubassets.com/images/icons/emoji/bowtie.png ":bowtie:")

List of contents
----------------

[](#list-of-contents)

- [Install](#install)
- [How to use](#how-to-use)
    - [Send requests](#send-requests)
    - [Send concurrent requests](#send-concurrent-requests)
    - [Event listeners](#event-listeners)
    - [Middlewares](#middlewares)
        - [How to create](#how-to-create)
        - [Global middlewares](#global-middlewares)
    - [Cache](#cache)
    - [Conditional configs](#conditional-configs)
    - [Clients](#Clients)
        - [Create clients](#create-clients)
        - [Run a client](#run-a-client)
        - [Send requests](#send-requests)
        - [Send concurrent requests](#send-concurrent-requests)
- [Testing](#testing)
- [Change log](#change-log)
- [Contributing](#contributing)
- [Security](#security)
- [Credits](#credits)
- [License](#license)

Install
-------

[](#install)

Via Composer

```
$ composer require shetabit/extractor
```

The service provider is registered by Laravel's package discovery, so there is nothing to add to `config/app.php`(or to `bootstrap/providers.php`).

How to use
----------

[](#how-to-use)

#### Send requests

[](#send-requests)

you can send requests to remote API using `Request` class, see the below example:

```
// at the top
use Shetabit\Extractor\Classes\Request;

//...

// create new request
$request = new Request();

// set api's url and method
$request->setUri($url)->setMethod('get');

// run the request and get data
$response = $request->fetch();

var_dump($response); // show given response
```

as you see, you can work with remote API in an easy way.

the `Request` has more methods to add `fields`, `headers` and etc.

```
use Shetabit\Extractor\Classes\Request;

//...
$request = new Request();

# Example 1:
$request
	->setUri('http://your-site.com')
	->setMethod('post')
	// add some headers
	->addHeader('Authorization', "Bearer dfaerfaeaeva1351adsfaecva")
	->addHeader('Accept', 'application/json')
	// add form parameters
	->addFormParam('email', $email)
    ->addFormParam('password', $password);

$response = $request->fetch(); // run request

# Example 2:
$request
	->setUri('http://your-site.com')
	->setMethod('get')
	// add query string
	->addQuery('page', $page)
	->addQuery('s', $search);

$response = $request->fetch(); // run request
```

#### Send concurrent requests

[](#send-concurrent-requests)

you can send concurrent requests like the below

```
use Shetabit\Extractor\Classes\Request;
use Shetabit\Extractor\Contracts\RequestInterface;

// ...

$request = new Request;

$responses = $request
    ->createBag()
    ->addRequest(function(RequestInterface $request) {
        $request->setUri('http://google.com/');
    })
    ->addRequest(function(RequestInterface $request) {
        $request->setUri('http://bing.com/');
    })
    ->fetch();
```

#### Event listeners

[](#event-listeners)

you can set `success` and `error` listener for each requests seperately. here is another example that uses `onSuccess` and `onError` listeners.

```
use Shetabit\Extractor\Classes\Request;
use Shetabit\Extractor\Contracts\RequestInterface;

// ...

$request = new Request;

# Example 1: using on success
$response = $request
	->setUri('http://google.com/')
	->onSuccess(function (ResponseInterface $response, RequestInterface $request) {
		echo $response->getBody();
	})
	->fetch();

# Example 2: using on error
$response = $request
	->setUri('http://yahoo.com/')
    ->onSuccess(function (ResponseInterface $response, RequestInterface $request) {
                echo 'success';
            })
            ->onError(function (ResponseInterface $response, RequestInterface $request) {
                echo 'fail';
            });

# Example 3: using request's bag
$response = $request
    ->createBag()
    ->addRequest(function (RequestInterface $request) {
        $request
            ->setUri('http://google.com/')
            ->onSuccess(function (ResponseInterface $response, RequestInterface $request) {
                echo $response->getBody();
            });
    })
    ->addRequest(function (RequestInterface $request) {
        $request
            ->setUri('http://yahoo.com/')
            ->onSuccess(function (ResponseInterface $response, RequestInterface $request) {
                echo 'success';
            })
            ->onError(function (ResponseInterface $response, RequestInterface $request) {
                echo 'fail';
            });
    })
    ->fetch();
```

#### Middlewares

[](#middlewares)

 [![](resources/images/middlewares-chain.png?raw=true)](resources/images/middlewares-chain.png?raw=true)

##### How to create

[](#how-to-create)

Middlewares can be created by running the below command

```
php artisan make:extractor-middleware test
```

The former command will create a middleware named `test` in `app\Http\RemoteRequests\Middlewares` path.

You can add a middleware to request like the below:

```
$request
    ->setUri('http://your-site.com')
    ->setMethod('get')
    ->middleware(new AuthMiddleware)
    ->fetch();
```

Multiple middlewares can be used by calling `middleware` method multiple times:

```
$request
    ->setUri('http://your-site.com')
    ->setMethod('get')
    ->middleware(new Test1)
    ->middleware(new Test2)
    ->fetch();
```

Each middleware has a `handle` method that can be used to handle requests and responses.

The following middleware would perform some task before the request is handled by the application:

```
public function handle(RequestInterface $request, Closure $next) : ?ResponseInterface
{
    if ($user->name == 'john') {
        $request->addQuery('name', 'john');
    }

    return $next($request);
}
```

However, this middleware would perform its task after the request is handled by the application:

```
public function handle(RequestInterface $request, Closure $next) : ?ResponseInterface
{
    $response = $next($request);

    // Perform action

    return $response;
}
```

A middleware can also answer on its own, without letting the request through — return a `ResponseInterface` instead of calling `$next`. Answering with `null` ends the request in a `RuntimeException`, since there is no response to hand back.

##### Global middlewares

[](#global-middlewares)

You can use `Request::withGlobalMiddlewares` to add global middlewares. global middlewares will be binded to all requests.

```
// in your AppServiceProvider

protected boot()
{
    Request::withGlobalMiddlewares([
        // list of middlewares
    ]);
}
```

in each request, you can unbind global middlewares, if you need them just use `withoutMiddleware` like the below:

```
// at the top
use Shetabit\Extractor\Classes\Request;

$url = 'http://google.com/';

$response = (new Request)
	->setUri($url)
	->withoutMiddleware(new TestMiddleware)
	->fetch();
```

##### Cache

[](#cache)

you can cache responses according to requests.

```
// at the top
use Shetabit\Extractor\Classes\Request;

$url = 'http://google.com/';
$ttl = 5; // 5 seconds

$response = (new Request)->setUri($url)->cache($ttl)->fetch();
```

**Notice:** `TTL` (Time To Live) is the same as `Laravel` cache.

```
// at the top
use Shetabit\Extractor\Classes\Request;

$url = 'http://google.com/';
$ttl = now()->addMinutes(10); // 10 minutes

$response = (new Request)->setUri($url)->cache($ttl)->fetch();
```

#### Conditional configs

[](#conditional-configs)

Sometimes you need to add some configs when a condition happens, in this kind of situations you can use the `when` method to add conditional configs.

```
# Example 1: simple

$request
    ->when('condition1', function($request) {
        $request
            ->setUri('http://your-site.com')
            ->setMethod('get')
            ->middleware(new AuthMiddleware);
    });

// Example 2: nested
$request
    ->when('condition1', function($request) {
        $request
            ->setUri('http://your-site.com')
            ->setMethod('get')
            ->middleware(new AuthMiddleware);
    })
    ->when('condition2', function($request) {
        $request
            ->setUri('http://shop-site.com')
            ->setMethod('get');
    })
    ->whenNot('condition3', function($request) {
        $request
            ->setUri('http://shop-site.com')
            ->setMethod('patch')
            ->when('condition4', function($request) {
                $request->setMethod('delete'); // sets method to delete
            });
    })
    ->fetch();
```

#### Client

[](#client)

You can encapsulate any request that exists between the **current microservice** and the **remote microservice** within a `Client`.

#### Create clients

[](#create-clients)

Clients can be created using a simple command

```
php artisan make:extractor-client  clientName
```

Clients will saved in `app/Http/RemoteRequests/Clients` by default.

lets create and example, imagine you have and remote Api (or microservice) and need to login into it.

then, your Login micro-client can be similar to below codes:

```
namespace App\Http\RemoteRequests\Clients\Auth;

use Shetabit\Extractor\Abstracts\MicroClientAbstract;
use Shetabit\Extractor\Contracts\ResponseInterface;

class Login extends MicroClientAbstract
{
    protected $mobile;
    protected $password;

    public function __construct($username, $password = null)
    {
        $this->username = $username;
        $this->password = $password;

        parent::__construct();
    }

    /**
     * Get requests' endpoint
     *
     * @return string
     */
    protected function getEndPoint()
    {
        return 'http://yoursite.com/api/v1/auth';
    }

    /**
     * Run client
     *
     * @return ResponseInterface
     * @throws \Exception
     */
    public function run() : ResponseInterface
    {
        $response = $this
            ->request
            ->setUri($this->getEndPoint())
            ->setMethod('post')
            ->addFormParam('username', $this->username)
            ->addFormParam('password', $this->password)
            ->fetch();

         return $response;
    }
}
```

#### Run a client

[](#run-a-client)

you can run the `Login` micro-client like the below (we have Login client example at the top)

```
// dump data
$username = 'test';
$password = 'something';

$client = new Login($username, $password);

// run client and login into remote service (remote api)
$response = $client->run();

// dump show response's body
var_dump($response->getBody());
```

as you see, client starts to work as you call the `run` method, fetches and returns a response.

On progress features
--------------------

[](#on-progress-features)

- internal error exceptions
- resource and API resource clients
- proxy requests to another server (middleware)

Testing
-------

[](#testing)

Every pull request and every push to `master` is checked by [GitHub Actions](https://github.com/shetabit/extractor/actions): the test suite runs on PHP 8.4 and 8.5, against Laravel 12 and 13 and against both the lowest and the highest supported dependencies, the coding style is checked with PHP\_CodeSniffer, the sources are analysed with PHPStan (level 7, with larastan) and the code coverage of the test suite is measured and has to stay above 95%.

The suite has two parts: `tests/Unit` covers the classes of the package on their own, and `tests/Feature` sends real requests over a real connection to a stub server the suite starts (`tests/Support/StubServer.php`), which answers with an echo of the request it received.

You can run the same checks locally. With PHP and Composer installed on your machine:

```
composer install

composer test           # run the test suite
composer test-coverage  # run the test suite and report code coverage
composer check-style    # check the coding style
composer fix-style      # fix the coding style where possible
composer analyse        # run static analysis
composer ci             # run all of the checks above
```

If you would rather not install PHP on your machine, the shipped `Dockerfile` and `Makefile` run everything inside a container:

```
make test              # run the test suite
make coverage          # run the test suite and report code coverage
make check-style       # check the coding style
make fix-style         # fix the coding style where possible
make analyse           # run static analysis
make ci                # run all of the checks above
make shell             # open a shell inside the container
make help              # list every available target
```

Another PHP version can be used with `make test PHP_VERSION=8.5`, and a single Laravel version with `make test-laravel LARAVEL=12`.

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.

Security
--------

[](#security)

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

Credits
-------

[](#credits)

- [Mahdi khanzadi](https://github.com/khanzadimahdi)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance65

Regular maintenance activity

Popularity26

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 50% 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 ~108 days

Recently: every ~276 days

Total

13

Last Release

1265d ago

Major Versions

v1.1.2 → v2.02019-11-25

v2.0.1 → v3.02020-02-18

v3.4.1 → v4.0.02023-02-27

### Community

Maintainers

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

![](https://avatars.githubusercontent.com/u/46709242?v=4)[Shetab](/maintainers/shetabit)[@shetabit](https://github.com/shetabit)

---

Top Contributors

[![khanzadimahdi](https://avatars.githubusercontent.com/u/6291970?v=4)](https://github.com/khanzadimahdi "khanzadimahdi (30 commits)")[![roshedgostarandev1](https://avatars.githubusercontent.com/u/52368299?v=4)](https://github.com/roshedgostarandev1 "roshedgostarandev1 (28 commits)")[![amirsadeghi1](https://avatars.githubusercontent.com/u/26359326?v=4)](https://github.com/amirsadeghi1 "amirsadeghi1 (1 commits)")[![Globerada](https://avatars.githubusercontent.com/u/26659866?v=4)](https://github.com/Globerada "Globerada (1 commits)")

---

Tags

laravel-microservicesmicroservicemicroservice-communicationapi clientmicro serviceextractorshetabitapi extractorapi remote clientmicro service clientmicro service data extractorremote micro service

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/shetabit-extractor/health.svg)

```
[![Health](https://phpackages.com/badges/shetabit-extractor/health.svg)](https://phpackages.com/packages/shetabit-extractor)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.7M3.4k](/packages/craftcms-cms)[fleetbase/core-api

Core Framework and Resources for Fleetbase API

1239.7k25](/packages/fleetbase-core-api)[illuminate/http

The Illuminate Http package.

11938.5M8.1k](/packages/illuminate-http)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3661.3M49](/packages/tencentcloud-tencentcloud-sdk-php)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

353.6k](/packages/eslazarev-wildberries-sdk)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5226.7k](/packages/simplestats-io-laravel-client)

PHPackages © 2026

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