samluvanda / http-client
A lightweight PHP HTTP client powered by cURL, offering retries, flexible headers, and fluent response parsing.
Requires
- php: ^8.0
- samluvanda/collection: ^1.0
README
๐ Introduction
A lightweight, fluent PHP HTTP client built entirely with cURL โ no dependencies, no bloat. This library gives you complete control over requests and responses while maintaining readability and simplicity in your codebase.
Designed for developers who value minimalism, precision, and testability in API communication.
๐ Why Use This Client?
- โจ Fluent, expressive syntax
- ๐ก Full control over headers, body, query params, and more
- โ๏ธ Built-in retry, timeout, and error handling mechanisms
- ๐ฆ Smart JSON parsing and collection-style access
- ๐ Rich status code and response helpers
- ๐ Supports all major auth schemes (Basic, Digest, Bearer, NTLM)
- ๐งต Pure cURL โ zero third-party HTTP layers
๐พ Installation
composer require samluvanda/http-client
Requirements:
- PHP 8.0+
curl
PHP extensionsamluvanda/collection
๐งช Quick Example
use HttpClient\Client; $client = new Client(); $response = $client ->withHeaders(['Authorization' => 'Bearer token']) ->withQueryParameters(['search' => 'books']) ->get('https://example.com/api/items'); if ($response->ok()) { print_r($response->json()); } else { echo "Request failed with status: " . $response->status(); }
You may also handle errors explicitly using fluent methods:
$response->throwIf(fn($res) => $res->status() >= 400);
๐ Full Documentation
See docs/DOCUMENTATION.md
for comprehensive usage instructions, supported methods, chaining examples, and advanced features like file uploads and raw body sending.
โ Minimum Requirements
- PHP >= 8.0
- cURL extension
samluvanda/collection
for JSON and array-like access
๐ค Contributing
Contributions, bug reports, and feature suggestions are welcome!
- Read the CONTRIBUTING.md guide
- Submit issues or PRs via GitHub
๐ Sponsor This Project
If you find this HTTP client useful, consider showing your support!
โ Buy me a coffee, fuel my late-night coding sessions, or just say thanks
๐ฌ s_luvanda@hotmail.com
๐ github.com/samluvanda
Every star, share, and sponsor keeps this project alive and evolving! ๐โจ
๐ License
This project is open-sourced under the MIT license.