Skip to content
/ yusr Public

πŸš€ Yusr: A lightweight, powerful PHP HTTP client inspired by Guzzle

License

Notifications You must be signed in to change notification settings

tal7aouy/yusr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

45 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ YusrClient - A Powerful PHP HTTP Client

YusrClient Logo

Latest Version on Packagist Total Downloads License

YusrClient is a robust and easy-to-use PHP HTTP client that simplifies making HTTP requests in your PHP applications. Built with modern PHP practices, it implements the PSR-18 HTTP Client interface and provides a fluent API for sending HTTP requests.

✨ Key Features

  • πŸ”’ PSR-18 HTTP Client compliant
  • πŸ›  Singleton pattern implementation
  • 🚦 Full HTTP method support (GET, POST, PUT, DELETE, PATCH)
  • πŸ”„ Automatic retry mechanism with exponential backoff
  • πŸ”§ Highly customizable request options
  • 🧩 Intuitive fluent interface
  • ⏱ Configurable timeouts
  • πŸ” SSL verification support

πŸ“¦ Installation

composer require tal7aouy/yusr

πŸš€ Quick Start

use Yusr\Http\YusrClient;

// Get client instance
$client = YusrClient::getInstance();

// Make a GET request
$response = $client->get('https://api.example.com/users');

// Work with response
$statusCode = $response->getStatusCode();
$data = $response->getBody()->getContents();
$headers = $response->getHeaders();

βš™οΈ Configuration

$client = YusrClient::getInstance([
    'timeout' => 30,
    'allow_redirects' => true,
    'verify' => true,
    'retry' => [
        'max_attempts' => 3,
        'delay' => 1000 // milliseconds
    ]
]);

πŸ“˜ Available Methods

HTTP Methods

$client->get(string $uri, array $options = []);
$client->post(string $uri, array $options = []);
$client->put(string $uri, array $options = []);
$client->delete(string $uri, array $options = []);
$client->patch(string $uri, array $options = []);

Request Options

  • query - Array of URL query parameters
  • headers - Custom request headers
  • body - Request body (for POST, PUT, PATCH)
  • timeout - Request timeout in seconds
  • allow_redirects - Follow redirects (boolean)
  • verify - SSL certificate verification
  • retry - Retry configuration for failed requests

πŸ”„ Retry Mechanism

YusrClient includes a sophisticated retry mechanism with exponential backoff:

$client = YusrClient::getInstance([
    'retry' => [
        'max_attempts' => 3,
        'delay' => 1000,
        'multiplier' => 2
    ]
]);

🀝 Contributing

Contributions are always welcome! Please read our Contributing Guide for details.

πŸ“ License

This project is licensed under the MIT License.

πŸ™ Support

If you find this package helpful, please consider giving it a star ⭐️