nixphp/client
最新稳定版本:v0.1.0
Composer 安装命令:
composer require nixphp/client
包简介
NixPHP Client Plugin to make simple http requests.
README 文档
README
nixphp/client
Simple HTTP client for PSR-18 requests — the NixPHP way.
This plugin provides a lightweight and dependency-free implementation
of the Psr\Http\Client\ClientInterface, using native PHP streams.
🧩 Part of the official NixPHP plugin collection. Perfect for internal API calls, simple integrations, and testing purposes.
📦 Features
- ✅ Implements
Psr\Http\Client\ClientInterface - ✅ No cURL, no external dependencies — pure PHP
- ✅ Supports custom handlers for testing/mocking
- ✅ Optional SSL verification toggle via config
- ✅ Integrates cleanly via
client()helper
📥 Installation
composer require nixphp/client
That’s it. The plugin will be autoloaded and ready to use.
🚀 Usage
✉️ Send a PSR-7 request
use Nyholm\Psr7\Request; $request = new Request('GET', 'https://example.com/api'); $response = client()->sendRequest($request); echo $response->getStatusCode(); echo (string) $response->getBody();
You can also pass a custom handler (e.g. for unit tests):
$response = client()->sendRequest($request, function($url, $opts) { return ['{"mock":true}', ['HTTP/1.1 200 OK']]; });
⚙️ Configuration
Disable SSL peer verification (e.g. for local dev):
// app/config.php return [ 'ssl_verify' => false ];
This disables verify_peer, verify_peer_name, and allows self-signed certs.
🔍 Internals
- Uses
file_get_contents()with PHP stream context. - Parses raw headers into a PSR-7-compatible
Responseobject. - Default response class:
Nyholm\Psr7\Response - Automatically included via
client()helper.
✅ Requirements
nixphp/framework>= 0.1.0nyholm/psr7>= 1.0 (used for PSR-7 implementation)
📄 License
MIT License.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-26