定制 tal7aouy/yusr 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tal7aouy/yusr

最新稳定版本:1.0.5

Composer 安装命令:

composer require tal7aouy/yusr

包简介

A lightweight HTTP client library for PHP inspired by Guzzle.

README 文档

README

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 ⭐️

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-12