Skip to content

An Interface to Connection between Services with REST in PHP

Notifications You must be signed in to change notification settings

snappmarket/php-rest-communicator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

About

An Interface to Connection between Services with REST in PHP

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages