samluvanda/http-client

A lightweight PHP HTTP client powered by cURL, offering retries, flexible headers, and fluent response parsing.

v1.0.0 2025-06-11 04:54 UTC

This package is auto-updated.

Last update: 2025-06-11 05:09:36 UTC


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:

๐Ÿงช 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!

๐Ÿ’– 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.