snappmarket / php-rest-communicator
该软件包最新版本(1.4.1)没有提供许可证信息。
1.4.1
2023-11-15 17:03 UTC
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: 2024-09-15 18:52:11 UTC
README
SnappMarket PHP Rest Communicator For Microservices
此软件包开发用于作为 SnappMarket 微服务 Rest 通信器。
要求
PHP >= 7.2.0
JSON PHP 扩展
安装
在您的 composer.json
文件中添加软件包。 $ composer require snappmarket/php-rest-communicator
基本用法
1. 使用 QueryString 的简单 GET 请求。
<?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. 使用 JSON 体的简单 POST 请求。
<?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; }