Skip to content

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.

License

Notifications You must be signed in to change notification settings

tylfin/maestro

 
 

Repository files navigation

Maintainability MIT licensed

Maestro

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.

Requirements

  • PHP 7.1 or greater
  • Composer

Installation

Composer way

composer require marcus-campos/maestro

Or add manually to your composer.json:

"marcus-campos/maestro": "dev-master"

Basic Usage

<?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;
    }
}

Response data

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;
 }

Senders

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;
 }

Supported Methods

  • 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()

About

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.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%