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
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-21