A light client built on Guzzle that simplifies the way you work with micro-services. It is based on method definitions and parameters for your URLs.
- PHP 7.1 or greater
- Composer
Composer way
composer require marcus-campos/maestro
Or add manually to your composer.json:
"marcus-campos/maestro": "dev-master"
<?php
namespace App\Platform\V1\Domains\App;
use Maestro\Rest;
class Products extends Rest
{
protected $url = 'https://mydomain.com/api/v1/'; // http://mydomain.com:9000/api/v1
/**
* @return array
*/
public function getProducts()
{
return $this
->get()
->setEndPoint('products')
->headers([
'Content-Type' => 'application/json'
])
->body( [
'ids' => [1,2,3,4,5]
])
->send()
->parse();
}
/**
* @return array
*/
public function getProduct()
{
return $this
->get()
->setEndPoint('product')
->send()
->parse();
}
/**
* @return array
*/
public function postNotification()
{
return $this
->get()
->setEndPoint('package/')
->headers([
'Content-Type' => 'application/json'
])
->body([
'message' => 'Tanks for all.',
'id' => [1]
])
->sendAsync()
->wait()
->parse()
->name;
}
}
By default the returns is a StdClass
, which gives you the freedom to treat the data the way you want. See the examples:
The way of Laravel
public function getProducts()
{
return collect(
$this
->get()
->setEndPoint('products')
->headers([
'Content-Type' => 'application/json'
])
->body([
'ids' => [1,2,3,4,5]
])
->send()
->parse());
}
You can choose assoc return.
Assoc way
public function postNotification()
{
return $this
->get()
->setEndPoint('package/')
->headers([
'Content-Type' => 'application/json'
])
->body([
'message' => 'Tanks for all.',
'id' => [1]
])
->send()
->assoc()
->parse()
->name;
}
Other way
public function postNotification()
{
return $this
->get()
->setEndPoint('package/')
->headers([
'Content-Type' => 'application/json'
])
->body([
'message' => 'Tanks for all.',
'id' => [1]
])
->sendAsync()
->wait()
->parse()
->name;
}
You can send in 2 ways: synchronous or asynchronous. See the examples:
Synchronous: ->send()
public function getProducts()
{
return collect($this
->get()
->setEndPoint('products')
->headers([
'Content-Type' => 'application/json'
])
->body([
'ids' => [1,2,3,4,5]
])
->send()
->parse());
}
Asynchronous: ->sendAsync()
public function postNotification()
{
return $this
->get()
->setEndPoint('package/')
->headers([
'Content-Type' => 'application/json'
])
->body([
'message' => 'Tanks for all.',
'id' => [1]
])
->sendAsync()
->wait()
->parse()
->name;
}
- GET
->get()
- POST
->post()
- PUT
->put()
- PATCH
->patch()
- DELETE
->delete()
- COPY
->copy()
- HEAD
->head()
- OPTIONS
->options()
- LINK
->link()
- UNLINK
->unlink()
- PURGE
->purge()
- LOCK
->lock()
- UNLOCK
->unlock()
- PROPFIND
->propfind()
- VIEW
->view()