Download the PHP package perfumer/microservices without Composer
On this page you can find all versions of the php package perfumer/microservices. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download perfumer/microservices
More information about perfumer/microservices
Files in perfumer/microservices
Package microservices
Short Description Set of classes for dealing with Perfumer microservices
License
Homepage https://github.com/perfumer/microservices
Informations about the package microservices
What is it
This is library to request Perfumerlabs microservices. Currently following microservices are supported:
All classes are autogenerated based on annotations.
Fast example
HTTP transactions
Library supports HTTP transactions.
Mechanism is very simple.
You connect storage provider.
Then write transaction, and after commit method all http-requests in transaction are stored to that storage.
If a request is failed, then its data is persisted in the storage. Then you can retry requests in the daemon or cron job.
Transaction example:
Example of daemon worker to resend requests we use:
Request debugging
If _debug=true is provided to Request class, then Microservice during requesting sets debug=true option to Guzzle client.
If it is enabled Guzzle prints some information about request to stdout.
Request catching
Library supports also any request catching servers for more convenient debugging. Request catching servers print requests as-is when they come. There are many free online request catching services in the google search.
Any microservice class allows request_catcher_host parameter in constructor options.
If it is defined, and _catch=true provided to Request class, then microservice class also sends special request to that host.
The request contains full request and response details in the body.
How to write annotations for HTTP methods
Say, we have a Crm service and want to generate annotation for GET /user request.
We open src/Contract/Crm.php and add class annotation like this:
To execute generation launch php generate.php. This annotation after generation creates a number of things:
- Base request class at
generated/src/Crm/Request/User/GetUserRequest.php - Empty request class at
src/Crm/Request/User/GetUserRequest.php - Base response class at
generated/src/Crm/Response/User/GetUserResponse.php - Empty response class at
src/Crm/Response/User/GetUserResponse.php - Base class at
generated/src/Crm/Crm.phpand/or methodgetUserin the class - Empty class at
src/Crm/Crm.phpif this is missing.
As you notice, request class path is generated by the next scheme:
Same as Response class:
Where microservice, model, action and submodule are annotation properties.
Also there are parameters to set:
urlmeans which URL will be requested. By default equal to model value.request_methodmeans HTTP-method to request with.fields- array of parameters to set to json body of the request.response_fields- array of parameters to get from response body.
For convenience, there a number of predefined annotations, which set some of parameters by themselves. For example:
is short equivalent of the full annotation above.
Contributing
Feel free to make any pull requests.