snappmarket/php-rest-communicator

There is no license information available for the latest version (1.4.1) of this package.

1.4.1 2023-11-15 17:03 UTC

README

Total Downloads Latest Stable Version License License

SnappMarket PHP Rest Communicator For Microservices

This package developed to use as SnappMarket Microservices Rest Communicator.

Requirements

  • PHP >= 7.2.0
  • JSON PHP Extension

installation

require package inside your composer.json file. $ composer require snappmarket/php-rest-communicator

Basic Usage

1. simple GET request with QueryString.
<?php
use SnappMarket\Communicator\Communicator;
use Illuminate\Log\Logger; // This is just an example for laravel logger that implements LoggerInterface
$base_url = 'your_base_ur_here';
$headers = ['x-Foo'=>'Bar'];
$logger = new Logger();
$uri = 'your_uri_here';
$parameters = [
    'page' => '2',
    'sort' => 'desc'
]; // parameters array acts as querystring (https://foo.bar/?page=2&sort=desc)
try {
    $communicator = new Communicator($base_url, $headers, $logger);
    $response = $communicator->request(Communicator::METHOD_GET,$uri,$parameters, $headers);
 } catch (Exception $exception){
    throw $exception;
}
2. simple POST request with JSON body.
<?php
use SnappMarket\Communicator\Communicator;
use Illuminate\Log\Logger; // This is just an example for laravel logger that implements LoggerInterface
$base_url = 'your_base_ur_here';
$headers = ['x-Foo'=>'Bar', 'content-type'=>Communicator::APPLICATION_JSON];
$logger = new Logger();
$uri = 'your_uri_here';
$parameters = [
    'phone_number' => '09xxxxxxxxx'
];
try {
    $communicator = new Communicator($base_url, $headers, $logger);
    $response = $communicator->request(Communicator::METHOD_POST,$uri,$parameters, $headers);
 } catch (Exception $exception){
    throw $exception;
}