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.
- π 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
composer require tal7aouy/yusr
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();
$client = YusrClient::getInstance([
'timeout' => 30,
'allow_redirects' => true,
'verify' => true,
'retry' => [
'max_attempts' => 3,
'delay' => 1000 // milliseconds
]
]);
$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 = []);
query
- Array of URL query parametersheaders
- Custom request headersbody
- Request body (for POST, PUT, PATCH)timeout
- Request timeout in secondsallow_redirects
- Follow redirects (boolean)verify
- SSL certificate verificationretry
- Retry configuration for failed requests
YusrClient includes a sophisticated retry mechanism with exponential backoff:
$client = YusrClient::getInstance([
'retry' => [
'max_attempts' => 3,
'delay' => 1000,
'multiplier' => 2
]
]);
Contributions are always welcome! Please read our Contributing Guide for details.
This project is licensed under the MIT License.
If you find this package helpful, please consider giving it a star βοΈ