hugphp / http
A delightful HTTP client with a human-readable API.
Fund package maintenance!
nunomaduro
Patreon
www.paypal.com/paypalme/enunomaduro
Requires
- php: ^8.3.0
- ext-curl: *
- justinrainbow/json-schema: ^6.2
Requires (Dev)
- laravel/pint: ^1.18.1
- peckphp/peck: ^0.1.1
- pestphp/pest: ^3.5.1
- pestphp/pest-plugin-type-coverage: ^3.1
- phpstan/phpstan: ^1.12.7
- rector/rector: ^1.2.8
- symfony/var-dumper: ^7.1.6
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.