{"id":18537968,"url":"https://github.com/shetabit/extractor","last_synced_at":"2026-03-11T05:31:59.661Z","repository":{"id":57049261,"uuid":"199120044","full_name":"shetabit/extractor","owner":"shetabit","description":"communicate with remote servers or microservices in an easy way","archived":false,"fork":false,"pushed_at":"2023-02-27T08:11:26.000Z","size":167,"stargazers_count":94,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-21T11:52:18.773Z","etag":null,"topics":["laravel-microservices","microservice","microservice-communication"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shetabit.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-27T05:23:43.000Z","updated_at":"2025-07-15T07:12:01.000Z","dependencies_parsed_at":"2024-11-06T19:45:05.977Z","dependency_job_id":"5e28464f-ad44-462d-b457-0e24e24a2a5c","html_url":"https://github.com/shetabit/extractor","commit_stats":{"total_commits":57,"total_committers":4,"mean_commits":14.25,"dds":0.5087719298245614,"last_synced_commit":"53b76e39dd4e85075f2c497433818a89db78f576"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/shetabit/extractor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shetabit%2Fextractor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shetabit%2Fextractor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shetabit%2Fextractor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shetabit%2Fextractor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shetabit","download_url":"https://codeload.github.com/shetabit/extractor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shetabit%2Fextractor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30372170,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T21:41:54.280Z","status":"online","status_checked_at":"2026-03-11T02:00:07.027Z","response_time":84,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel-microservices","microservice","microservice-communication"],"created_at":"2024-11-06T19:41:28.864Z","updated_at":"2026-03-11T05:31:59.635Z","avatar_url":"https://github.com/shetabit.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"resources/images/microservices-communication.png?raw=true\"\u003e\n\u003c/p\u003e\n\n# Laravel Extractor\n\nCommunicate with **remote servers** or **microservices** in an easy way.\n\nAll requests and responses can be **cached** and **manipulated** on runtime using **middlewares**.\n\n[Donate me](https://yekpay.me/mahdikhanzadi) if you like this package :sunglasses: :bowtie:\n\n## List of contents\n\n- [Install](#install)\n- [How to use](#how-to-use)\n  - [Send requests](#send-requests)\n  - [Send concurrent requests](#send-concurrent-requests)\n  - [Event listeners](#event-listeners)\n  - [Middlewares](#middlewares)\n  \t- [How to create](#how-to-create)\n  \t- [Global middlewares](#global-middlewares)\n  - [Cache](#cache)\n  - [Conditional configs](#conditional-configs)\n  - [Clients](#Clients)\n    - [Create clients](#create-clients)\n    - [Run a client](#run-a-client)\n    - [Send requests](#send-requests)\n    - [Send concurrent requests](#send-concurrent-requests)\n- [Change log](#change-log)\n- [Contributing](#contributing)\n- [Security](#security)\n- [Credits](#credits)\n- [License](#license)\n\n## Install\n\nVia Composer\n\n```bash\n$ composer require shetabit/extractor\n```\n\nIf you are using `Laravel 5.5` or higher then you don't need to add the provider and alias.\n\nIn your `config/app.php` file add below lines.\n\n```php\n# In your providers array.\n'providers' =\u003e [\n\t...\n\tShetabit\\Extractor\\Providers\\ExtractorServiceProvider::class,\n]\n```\n\n## How to use\n\n#### Send requests\n\nyou can send requests to remote API using `Request` class, see the below example:\n\n```php\n// at the top\nuse Shetabit\\Extractor\\Classes\\Request;\n\n//...\n\n// create new request\n$request = new Request();\n\n// set api's url and method\n$request-\u003esetUri($url)-\u003esetMethod('get');\n\n// run the request and get data\n$response = $request-\u003efetch();\n\nvar_dump($response); // show given response\n```\n\nas you see, you can work with remote API in an easy way.\n\nthe `Request` has more methods to add `fields`, `headers` and etc.\n\n```php\nuse Shetabit\\Extractor\\Classes\\Request;\n\n//...\n$request = new Request();\n\n\n# Example 1:\n$request\n\t-\u003esetUri('http://your-site.com')\n\t-\u003esetMethod('post')\n\t// add some headers\n\t-\u003eaddHeader('Authorization', \"Bearer dfaerfaeaeva1351adsfaecva\")\n\t-\u003eaddHeader('Accept', 'application/json')\n\t// add form parameters\n\t-\u003eaddFormParam('email', $email)\n    -\u003eaddFormParam('password', $password);\n\n$response = $request-\u003efetch(); // run request\n\n\n# Example 2:\n$request\n\t-\u003esetUri('http://your-site.com')\n\t-\u003esetMethod('get')\n\t// add query string\n\t-\u003eaddQuery('page', $page)\n\t-\u003eaddQuery('s', $search);\n\n$response = $request-\u003efetch(); // run request\n```\n\n#### Send concurrent requests\n\nyou can send concurrent requests like the below\n\n```php\nuse Shetabit\\Extractor\\Classes\\Request;\nuse Shetabit\\Extractor\\Contracts\\RequestInterface;\n\n// ...\n\n$request = new Request;\n\n$responses = $request\n    -\u003ecreateBag()\n    -\u003eaddRequest(function(RequestInterface $request) {\n        $request-\u003esetUri('http://google.com/');\n    })\n    -\u003eaddRequest(function(RequestInterface $request) {\n        $request-\u003esetUri('http://bing.com/');\n    })\n    -\u003efetch();\n```\n\n#### Event listeners\n\nyou can set `success` and `error` listener for each requests seperately. here is another example that uses `onSuccess` and `onError` listeners.\n\n```php\nuse Shetabit\\Extractor\\Classes\\Request;\nuse Shetabit\\Extractor\\Contracts\\RequestInterface;\n\n// ...\n\n$request = new Request;\n\n# Example 1: using on success\n$response = $request\n\t-\u003esetUri('http://google.com/')\n\t-\u003eonSuccess(function (ResponseInterface $response, RequestInterface $request) {\n\t\techo $response-\u003egetBody();\n\t})\n\t-\u003efetch();\n\n\n# Example 2: using on error\n$response = $request\n\t-\u003esetUri('http://yahoo.com/')\n    -\u003eonSuccess(function (ResponseInterface $response, RequestInterface $request) {\n                echo 'success';\n            })\n            -\u003eonError(function (ResponseInterface $response, RequestInterface $request) {\n                echo 'fail';\n            });\n\n\n# Example 3: using request's bag\n$response = $request\n    -\u003ecreateBag()\n    -\u003eaddRequest(function (RequestInterface $request) {\n        $request\n            -\u003esetUri('http://google.com/')\n            -\u003eonSuccess(function (ResponseInterface $response, RequestInterface $request) {\n                echo $response-\u003egetBody();\n            });\n    })\n    -\u003eaddRequest(function (RequestInterface $request) {\n        $request\n            -\u003esetUri('http://yahoo.com/')\n            -\u003eonSuccess(function (ResponseInterface $response, RequestInterface $request) {\n                echo 'success';\n            })\n            -\u003eonError(function (ResponseInterface $response, RequestInterface $request) {\n                echo 'fail';\n            });\n    })\n    -\u003efetch();\n```\n\n#### Middlewares\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"resources/images/middlewares-chain.png?raw=true\"\u003e\n\u003c/p\u003e\n\n\n\n##### How to create\n\nMiddlewares can be created by running the below command\n\n```shell\nphp artisan make:extractor-middleware test\n```\n\nThe former command will create a middleware named `test` in `app\\Http\\RemoteRequests\\Middlewares` path.\n\nYou can add a middleware to request like the below:\n\n```php\n$request\n    -\u003esetUri('http://your-site.com')\n    -\u003esetMethod('get')\n    -\u003emiddleware(new AuthMiddleware)\n    -\u003efetch();\n```\n\nMultiple middlewares can be used by calling `middleware` method multiple times:\n\n```php\n$request\n    -\u003esetUri('http://your-site.com')\n    -\u003esetMethod('get')\n    -\u003emiddleware(new Test1)\n    -\u003emiddleware(new Test2)\n    -\u003efetch();\n```\n\nEach middleware has a `handle` method that can be used to handle requests and responses.\n\nThe following middleware would perform some task before the request is handled by the application:\n\n```php\npublic function handle($request, Closure $next) {\n    if($user-\u003ename == 'john') {\n        $request-\u003eaddQuery('name', 'john');\n    }\n\n    return $next($request);\n}\n```\n\nHowever,  this middleware would perform its task after the request is handled by the application:\n\n```php\npublic function handle($request, Closure $next)\n{\n    $response = $next($request);\n\n    // Perform action\n\n    return $response;\n}\n```\n\n##### Global middlewares\n\nYou can use `Request::withGlobalMiddlewares` to add global middlewares.\nglobal middlewares will be binded to all requests.\n\n```php\n\n// in your AppServiceProvider\n\nprotected boot()\n{\n    Request::withGlobalMiddlewares([\n        // list of middlewares\n    ]);\n}\n\n```\n\nin each request, you can unbind global middlewares, if you need them just use `withoutMiddleware` like the below:\n\n```php\n// at the top\nuse Shetabit\\Extractor\\Classes\\Request;\n\n$url = 'http://google.com/';\n\n$response = (new Request)\n\t-\u003esetUri($url)\n\t-\u003ewithoutMiddleware(new TestMiddleware)\n\t-\u003efetch();\n```\n\n\n##### Cache\n\nyou can cache responses according to requests.\n\n```php\n// at the top\nuse Shetabit\\Extractor\\Classes\\Request;\n\n$url = 'http://google.com/';\n$ttl = 5; // 5 seconds\n\n$response = (new Request)-\u003esetUri($url)-\u003ecache($ttl)-\u003efetch();\n```\n\n**Notice:** `TTL` (Time To Live) is the same as `Laravel` cache.\n\n```php\n// at the top\nuse Shetabit\\Extractor\\Classes\\Request;\n\n$url = 'http://google.com/';\n$ttl = now()-\u003eaddMinutes(10); // 10 minutes\n\n$response = (new Request)-\u003esetUri($url)-\u003ecache($ttl)-\u003efetch();\n```\n\n#### Conditional configs\n\nSometimes 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.\n\n```php\n# Example 1: simple\n\n$request\n    -\u003ewhen('condition1', function($request) {\n        $request\n            -\u003esetUri('http://your-site.com')\n            -\u003esetMethod('get')\n            -\u003emiddleware(new AuthMiddleware);\n    });\n\n\n// Example 2: nested\n$request\n    -\u003ewhen('condition1', function($request) {\n        $request\n            -\u003esetUri('http://your-site.com')\n            -\u003esetMethod('get')\n            -\u003emiddleware(new AuthMiddleware);\n    })\n    -\u003ewhen('condition2', function($request) {\n        $request\n            -\u003esetUri('http://shop-site.com')\n            -\u003esetMethod('get');\n    })\n    -\u003ewhenNot('condition3', function($request) {\n        $request\n            -\u003esetUri('http://shop-site.com')\n            -\u003esetMethod('patch')\n            -\u003ewhen('condition4', function($request) {\n                $request-\u003esetMethod('delete'); // sets method to delete\n            });\n    })\n    -\u003efetch();\n```\n\n#### Client\n\nYou can encapsulate any request that exists between the **current microservice** and the **remote microservice** within a `Client`.\n\n#### Create clients\n\nClients can be created using a simple command\n\n```bash\nphp artisan make:extractor-client  clientName\n```\n\nClients will saved in `app/Http/RemoteRequests/Clients` by default.\n\nlets create and example, imagine you have and remote Api (or microservice) and need to login into it.\n\nthen, your Login micro-client can be similar to below codes:\n\n```php\nnamespace App\\Http\\RemoteRequests\\Clients\\Auth;\n\nuse Shetabit\\Extractor\\Abstracts\\MicroClientAbstract;\nuse Shetabit\\Extractor\\Contracts\\ResponseInterface;\n\nclass Login extends MicroClientAbstract\n{\n    protected $mobile;\n    protected $password;\n\n    public function __construct($username, $password = null)\n    {\n        $this-\u003eusername = $username;\n        $this-\u003epassword = $password;\n\n        parent::__construct();\n    }\n\n    /**\n     * Get requests' endpoint\n     *\n     * @return string\n     */\n    protected function getEndPoint()\n    {\n        return 'http://yoursite.com/api/v1/auth';\n    }\n\n    /**\n     * Run client\n     *\n     * @return ResponseInterface\n     * @throws \\Exception\n     */\n    public function run() : ResponseInterface\n    {\n        $response = $this\n            -\u003erequest\n            -\u003esetUri($this-\u003egetEndPoint())\n            -\u003esetMethod('post')\n            -\u003eaddFormParam('username', $this-\u003eusername)\n            -\u003eaddFormParam('password', $this-\u003epassword)\n            -\u003efetch();\n\n         return $response;\n    }\n}\n```\n\n#### Run a client\n\nyou can run the `Login` micro-client like the below (we have Login client example at the top)\n\n```php\n// dump data\n$username = 'test';\n$password = 'something';\n\n$client = new Login($username, $password);\n\n// run client and login into remote service (remote api)\n$response = $client-\u003erun();\n\n// dump show response's body\nvar_dump($response-\u003egetBody());\n```\n\nas you see, client starts to work as you call the `run` method, fetches and returns a response.\n\n## On progress features\n\n- internal error exceptions\n- resource and API resource clients\n- proxy requests to another server (middleware)\n\n## Change log\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.\n\n## Security\n\nIf you discover any security related issues, please email khanzadimahdi@gmail.com instead of using the issue tracker.\n\n## Credits\n\n- [Mahdi khanzadi][link-author]\n- [All Contributors][link-contributors]\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n[link-packagist]: https://packagist.org/packages/shetabit/extractor\n[link-code-quality]: https://scrutinizer-ci.com/g/shetabit/extractor\n[link-author]: https://github.com/khanzadimahdi\n[link-contributors]: ../../contributors\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshetabit%2Fextractor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshetabit%2Fextractor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshetabit%2Fextractor/lists"}