reaway/http-client
Composer 安装命令:
composer require reaway/http-client
包简介
HTTP Client implementation using PHP cURL with PSR-7, PSR-17, PSR-18 support
README 文档
README
A lightweight HTTP client library based on PHP cURL, supporting PSR-7, PSR-17, and PSR-18 standards.
Features
- ✅ PSR-7 (HTTP Messages) compatible
- ✅ PSR-17 (HTTP Factories) compatible
- ✅ PSR-18 (HTTP Client) compatible
- ✅ Simple and easy-to-use API
- ✅ Support for GET, POST, JSON, and file upload requests
- ✅ Custom request headers
- ✅ Query parameter support
- ✅ Stream-based file upload (suitable for large files)
Installation
composer require reaway/http-client
Requirements
- PHP >= 8.0
- ext-curl
Quick Start
<?php use HttpClient\HttpClient; use HttpClient\Psr17\RequestFactory; use HttpClient\Psr17\StreamFactory; use HttpClient\Psr18\Client; // Create HttpClient instance $client = new HttpClient( new Client(), // PSR-18 ClientInterface new RequestFactory(), // PSR-17 RequestFactoryInterface new StreamFactory() // PSR-17 StreamFactoryInterface ); // Send GET request $response = $client->get('https://api.example.com/users'); echo $response->getBody();
Usage
GET Request
// Simple GET request $response = $client->get('https://api.example.com/users'); // With query parameters $response = $client->get( 'https://api.example.com/users', ['page' => 1, 'limit' => 10], ['Authorization' => 'Bearer token'] );
POST Request (Form Data)
$response = $client->postForm( 'https://api.example.com/users', [ 'name' => 'John Doe', 'email' => 'john@example.com' ], ['Authorization' => 'Bearer token'] );
POST Request (JSON)
$response = $client->postJson( 'https://api.example.com/users', [ 'name' => 'John Doe', 'email' => 'john@example.com', 'address' => [ 'city' => 'New York', 'street' => '5th Avenue' ] ], ['Authorization' => 'Bearer token'] );
POST 请求(multipart/form-data)
$response = $client->postMultipart( 'https://api.example.com/upload', // Regular form fields ['description' => 'File upload test'], // File fields - Full format [ 'avatar' => [ 'path' => '/path/to/avatar.jpg', 'filename' => 'avatar.jpg', 'type' => 'image/jpeg' ], 'document' => [ 'path' => '/path/to/document.pdf', 'filename' => 'report.pdf', 'type' => 'application/pdf' ] ], ['Authorization' => 'Bearer token'] ); // Shorthand format for file fields $response = $client->postMultipart( 'https://api.example.com/upload', [], [ 'file' => ['/path/to/file.zip', 'archive.zip', 'application/zip'] ] );
Set Default Headers
$client->setDefaultHeaders([ 'User-Agent' => 'MyApp/1.0', 'X-API-Key' => 'your-api-key' ]);
Send Raw Request
use Psr\Http\Message\RequestInterface; $request = $requestFactory->createRequest('GET', 'https://api.example.com/users'); $response = $client->send($request);
API Reference
HttpClient Methods
| Method | Description |
|---|---|
setDefaultHeaders(array $headers): self |
Set default request headers |
get(string $url, array $headers = [], array $queryParams = []): ResponseInterface |
Send GET request |
post(string $url, array $data = [], array $headers = []): ResponseInterface |
Send POST request (form data) |
postJson(string $url, array|object $data, array $headers = []): ResponseInterface |
Send POST request (JSON) |
upload(string $url, array $fields = [], array $files = [], array $headers = []): ResponseInterface |
Send multipart/form-data request (file upload) |
send(RequestInterface $request): ResponseInterface |
Send raw PSR-7 request |
Testing
./vendor/bin/phpunit
License
This project is licensed under the MIT License.
reaway/http-client 适用场景与选型建议
reaway/http-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 reaway/http-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 reaway/http-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-18