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.
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
- Change log
- Contributing
- Security
- Credits
- License
Install
Via Composer
If you are using Laravel 5.5
or higher then you don't need to add the provider and alias.
In your config/app.php
file add below lines.
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:
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)
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
illuminate/broadcasting Version 5.8.*|6.*|7.*|8.*|9.*|10.*
illuminate/support Version 5.8.*|6.*|7.*|8.*|9.*|10.*
guzzlehttp/guzzle Version 6.2.*|7.*