This package developed to use as SnappMarket Microservices Rest Communicator.
PHP >= 7.2.0
JSON PHP Extension
require package inside your composer.json
file.
$ composer require snappmarket/php-rest-communicator
<?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;
}
<?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;
}