定制 navinchinnasamy/custom-http-client 二次开发

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

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

navinchinnasamy/custom-http-client

Composer 安装命令:

composer require navinchinnasamy/custom-http-client

包简介

A simple Custom HTTP client package for Laravel applications.

README 文档

README

A flexible HTTP client manager in PHP that allows you to choose between different HTTP clients, such as Guzzle and PHP Streams, based on your requirements.

Table of Contents

Installation

You can install this package using Composer. Run the following command in your terminal:

composer require navin/custom-http-client

Usage

To use the Custom HTTP Client, you need to create an instance of the desired HTTP client using the HttpClientFactory. You can specify which client to use based or you can just get any one of the HTTP client available in your system/server.

use CustomHTTP\HttpClientFactory;

$clientType = 'curl';
$httpClient = HttpClientFactory::create($clientType);

// Make a GET request
try {
    $response = $httpClient->get('https://example.com');
    echo $response;
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

OR

use CustomHTTP\HttpClientFactory;

$httpClient = new HttpClientFactory()->getClient();

// Make a GET request
try {
    $response = $httpClient->get('https://example.com');
    echo $response;
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

Supported HTTP Clients

PHP cURL: A library that allows you to connect and communicate with different types of servers using various protocols, including HTTP.

PHP Streams: A built-in PHP method for handling HTTP requests using streams.

Examples

Making a POST Request Here's how to make a POST request using the custom HTTP client:

try {
    $response = $httpClient->post('https://example.com/api', [
        'body' => [
            'key1' => 'value1',
            'key2' => 'value2',
        ],
        'headers' => [
            'api_key' => 'your-api-key'
        ]
    ]);
    echo $response;
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

Other methods can also be used as like below:

try {
    $response = $httpClient->request('https://example.com/api', 'PUT', [
        'body' => [
            'key1' => 'value1',
            'key2' => 'value2',
        ],
        'headers' => [
            'api_key' => 'your-api-key'
        ]
    ]);
    echo $response;
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

License

This project is licensed under the MIT License.

Conclusion

Feel free to modify any sections to better suit your package's specifics or to include additional features and documentation as needed. If you need further customization or additional sections, let me know!

Mail ID: navinchinnasamy@gmail.com

统计信息

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

GitHub 信息

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

其他信息

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