chocofamilyme / smart-http
服务间通信的 HTTP 客户端
1.1.1
2022-09-16 09:50 UTC
Requires
- php: >= 7.2.0
- ext-json: *
- ejsmont-artur/php-circuit-breaker: ~0.1
- guzzlehttp/guzzle: ^7.2
- psr/simple-cache: ^1.0
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-16 14:28:51 UTC
README
基于 Guzzle 的 HTTP 客户端,具有预置设置。可以执行配置好的请求 - Request 类,也可以自行精细调整请求 - Client 类
功能
要求
- PHP 7.2+
- guzzlehttp/guzzle 6.0+
- ejsmont-artur/php-circuit-breaker
安装
$ composer require chocofamilyme/smart-http
示例
简单的 GET 请求
$request = new Chocofamily\SmartHttp\Http\Request($config, $cache); $options = [ 'serviceName' => 'serviceA', 'cache' => 3600, 'data' => [ 'id' => 1 ], ]; $response = $request->send('GET', 'http://service/item', $options);
参数 $cache
是可选的。如果不存在,则不缓存请求并自动关闭服务。
包含对象 $config 的参数
$options 参数
缓存响应
可以在参数 cache 指定的时间内缓存请求,缓存键是请求的 url。在基于 url 形成键时,将忽略查询参数 correlation_id 和 span_id