kiwfy / request-service-php
6.0.0
2023-11-02 17:41 UTC
Requires
- php: ^8.2
- guzzlehttp/guzzle: ^7.8
Requires (Dev)
- mockery/mockery: ^1.6
- phpmd/phpmd: ^2.14
- phpunit/phpunit: ^9.6
- squizlabs/php_codesniffer: ^3.7
README
使用Guzzle基础库发送请求到任何服务的PHP库。适用于微服务架构
安装
版本 6.0.0 需要 PHP 8.2
版本 5.0.0 需要 PHP 8.1
版本 4.0.0 需要 PHP 7.4
版本 3.0.0 需要 PHP 7.3
版本 2.0.0 需要 PHP 7.2
版本 1.0.0 需要 PHP 7.1
推荐通过Composer安装。
composer require not-empty/request-service-php-lib
用法
请求json
use RequestService\Request; $config = [ 'your-service' => [ 'url' => 'https://jsonplaceholder.typicode.com', ], ]; $sample = new Request($config); $response = $sample->sendRequest( 'your-service', 'GET', 'todos/1' ); var_dump($response);
请求流
use RequestService\Request; $config = [ 'your-service' => [ 'url' => 'https://developer.marvel.com/', 'json' => false, ], ]; $sample = new Request($config); $header = [ 'stream' => true, ]; $response = $sample->sendRequest( 'your-service', 'GET', 'docs', $header ); var_dump($response);
如果您需要一个运行或测试的环境,可以按照以下方式构建和安装依赖项
docker build --build-arg PHP_VERSION=8.2-cli -t not-empty/request-service-php-lib:php82 -f contrib/Dockerfile .
访问容器
docker run -v ${PWD}/:/var/www/html -it not-empty/request-service-php-lib:php82 bash
验证所有依赖项是否已安装
composer install --no-dev --prefer-dist
并运行
php sample/request-sample.php php sample/request-image-sample.php
开发
想贡献力量?太好了!
该项目使用简单的代码。更改您的文件时请谨慎更新!任何新代码都将仅在接受所有验证后接受。
为确保整个项目正常
首先您需要构建一个正确环境来安装所有依赖项
docker build --build-arg PHP_VERSION=8.2-cli -t not-empty/request-service-php-lib:php82 -f contrib/Dockerfile .
访问容器
docker run -v ${PWD}/:/var/www/html -it not-empty/request-service-php-lib:php82 bash
安装所有依赖项
composer install --dev --prefer-dist
运行所有验证
composer check
Not Empty Foundation - 自由代码,自由思想