hugphp/http
最新稳定版本:v1.0.0
Composer 安装命令:
composer require hugphp/http
包简介
A delightful HTTP client with a human-readable API.
README 文档
README
HugPHP HTTP Client
A delightful HTTP client for PHP with a human-readable API, designed to make HTTP requests simple, lovable, and powerful.
Requires PHP 8.3+ and
ext-curl
Installation
Add HugPHP HTTP to your project using Composer:
composer require hugphp/http
Features
- Fluent, chainable API for intuitive request building.
- Built-in JSON support for easy data sending and parsing.
- Optional SSL verification toggle for flexibility.
- Lightweight and dependency-free (uses native cURL).
1. Example Usage
use HugPHP\Http\Client; $client = new Client(); // Simple GET request (SSL verification enabled by default) $response = $client->to('https://api.example.com/data')->get(); echo $response->body(); // POST with JSON, disabling SSL verification $response = $client->to('https://api.example.com/post') ->withHeader('Authorization', 'Bearer token') ->sendJson(['name' => 'HugPHP']) ->withOutSSLCertificate() // Disables SSL verification ->post(); print_r($response->json()); // Fetch JSON directly $data = $client->to('https://api.example.com/users/1') ->withOutSSLCertificate() ->get() ->json(); echo $data['name'];
2. Example Usage
use HugPHP\Http\Client; $client = new Client(); // GET with rate limiting $client->to('https://api.example.com/data') ->withRateLimit(5, 'minute') ->get(); // POST with JSON and debugging $client->to('https://api.example.com/post') ->withHeader('Authorization', 'Bearer token') ->sendJson(['name' => 'HugPHP']) ->debug() ->post(); // Validate and transform response class User { public int $id; public string $name; } $user = $client->to('https://api.example.com/user') ->withOutSSLCertificate() ->validateSchema('user-schema.json', User::class); echo $user->name; // Mock for testing $client->mock('https://example.com', ['status' => 200, 'body' => '{"fake": true}']); $data = $client->to('https://example.com')->get()->json();
Development
🧹 Keep a modern codebase with Pint:
composer lint
✅ Run refactors using Rector
composer refacto
⚗️ Run static analysis using PHPStan:
composer test:types
✅ Run unit tests using PEST
composer test:unit
🚀 Run the entire test suite:
composer test
HugPHP HTTP was created by Micheal Ataklt under the MIT license.
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-27
