snappmarket / php-rest-communicator
Installs: 910
Dependents: 5
Suggesters: 0
Security: 0
Stars: 3
Watchers: 9
Forks: 1
Open Issues: 0
pkg:composer/snappmarket/php-rest-communicator
Requires
- php: >=7.1
- ext-json: *
- guzzlehttp/guzzle: >=6.0
- psr/http-message: ^1.0
- psr/log: ^1.0
This package is auto-updated.
Last update: 2025-10-15 21:20:13 UTC
README
SnappMarket PHP Rest Communicator For Microservices
This package developed to use as SnappMarket Microservices Rest Communicator.
Requirements
PHP >= 7.2.0JSON 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; }