Download the PHP package shetabit/extractor without Composer
On this page you can find all versions of the php package shetabit/extractor. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download shetabit/extractor
More information about shetabit/extractor
Files in shetabit/extractor
Package extractor
Short Description a `micro client` generator to communicate between `micro services` in laravel apps
License MIT
Homepage https://github.com/shetabit/extractor
Informations about the package extractor
Laravel 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 if you like this package :sunglasses: :bowtie:
List of contents
- Install
- How to use
- Send requests
- Send concurrent requests
- Event listeners
- Middlewares
- How to create
- Global middlewares
- Cache
- Conditional configs
- Clients
- Create clients
- Run a client
- Send requests
- Send concurrent requests
- Testing
- Change log
- Contributing
- Security
- Credits
- License
Install
Via Composer
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
Send requests
you can send requests to remote API using Request class, see the below example:
as you see, you can work with remote API in an easy way.
the Request has more methods to add fields, headers and etc.
Send concurrent requests
you can send concurrent requests like the below
Event listeners
you can set success and error listener for each requests seperately. here is another example that uses onSuccess and onError listeners.
Middlewares
How to create
Middlewares can be created by running the below command
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:
Multiple middlewares can be used by calling middleware method multiple times:
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:
However, this middleware would perform its task after the request is handled by the application:
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
You can use Request::withGlobalMiddlewares to add global middlewares.
global middlewares will be binded to all requests.
in each request, you can unbind global middlewares, if you need them just use withoutMiddleware like the below:
Cache
you can cache responses according to requests.
Notice: TTL (Time To Live) is the same as Laravel cache.
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.
Client
You can encapsulate any request that exists between the current microservice and the remote microservice within a Client.
Create clients
Clients can be created using a simple command
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:
Run a client
you can run the Login micro-client like the below (we have Login client example at the top)
as you see, client starts to work as you call the run method, fetches and returns a response.
On progress features
- internal error exceptions
- resource and API resource clients
- proxy requests to another server (middleware)
Testing
Every pull request and every push to master is checked by GitHub 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:
If you would rather not install PHP on your machine, the shipped Dockerfile and Makefile run everything inside a
container:
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
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONDUCT for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Mahdi khanzadi
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of extractor with dependencies
guzzlehttp/guzzle Version ^7.8.2|^8.0
illuminate/console Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.0