joshuaify/guzzlelib
Composer 安装命令:
composer require joshuaify/guzzlelib
包简介
A wrapper library for Guzzle HTTP client
README 文档
README
Guzzlelib is a PHP wrapper library for Guzzle HTTP client, providing a simplified interface for making HTTP requests. It offers an easy-to-use API for GET, POST, PUT, PATCH, and DELETE requests, with built-in error handling and response parsing.
This library can be used with PHP 7.2+ and is compatible with popular PHP frameworks, including Laravel, Symfony, CodeIgniter, Zend, Yii, CakePHP, and Slim. It's ideal for any PHP application that requires streamlined API communication.
Requirements
- PHP 7.2 or higher
- Composer (for dependency management)
- Guzzle HTTP client
Installation
You can install Guzzlelib using Composer. Run the following command in your project directory:
composer require joshuaify/guzzlelib
Usage
Initialization
First, include the Guzzlelib class in your PHP file:
use joshuaify\API\Guzzlelib;
or
require 'path/to/your/vendor/joshuaify/guzzlelib/src/Guzzlelib.php';
Then, create an instance of Guzzlelib:
$guzzlelib = new Guzzlelib([ 'base_uri' => 'https://api.example.com', 'timeout' => 30.0, 'headers' => [ 'Authorization' => 'Bearer your-token-here' ] ]);
Making Requests
GET Request
$response = $guzzlelib->getRequest('/users', ['page' => 1]);
POST Request
$response = $guzzlelib->postRequest('/users', [ 'name' => 'John Doe', 'email' => 'john@example.com' ]);
PUT Request
$response = $guzzlelib->putRequest('/users/1', [ 'name' => 'Jane Doe' ]);
PATCH Request
$response = $guzzlelib->patchRequest('/users/1', [ 'email' => 'jane@example.com' ]);
DELETE Request
$response = $guzzlelib->deleteRequest('/users/1');
Handling Responses
All request methods return an array with two keys: code and body.
code: The HTTP status code of the response.body: The decoded JSON body of the response.
Example:
$response = $guzzlelib->getRequest('/users'); if ($response['code'] === 200) { $users = $response['body']; // Process $users data } else { // Handle error echo "Error: " . json_encode($response['body']); }
Error Handling
If a request fails, Guzzlelib will return an array with an error key set to true and a message describing the error.
$response = $guzzlelib->getRequest('/non-existent-endpoint'); if (isset($response['error']) && $response['error'] === true) { echo "Error occurred: " . $response['message']; }
Configuration Options
When initializing Guzzlelib, you can pass an array of configuration options:
base_uri: The base URL for all requests.timeout: The timeout for requests in seconds.headers: An array of default headers to be sent with each request.auth: Authentication method (e.g., ['username', 'password'] for Basic Auth).proxy: Proxy settings.verify: SSL certificate verification (set tofalseto disable).connect_timeout: The number of seconds to wait while trying to connect to a server.cookies: Set totrueto use a shared cookie session, or provide an instance ofGuzzleHttp\Cookie\CookieJarInterface.allow_redirects: Set tofalseto disable redirects.debug: Set totrueto enable debug output.http_errors: Set tofalseto disable throwing exceptions on HTTP protocol errors (4xx and 5xx responses).
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This library is open-sourced software licensed under the MIT license.
joshuaify/guzzlelib 适用场景与选型建议
joshuaify/guzzlelib 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 09 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「api」 「client」 「codeigniter」 「laravel」 「api-requests」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 joshuaify/guzzlelib 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 joshuaify/guzzlelib 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 joshuaify/guzzlelib 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Mock PSR-18 HTTP client
Asynchronous MQTT client built on React
Client for Google Directions API to add interpolated points to a route consisting of given coordinates.
Alfabank REST API integration
A Flickr wrapper to allow you to call the Flickr api with Guzzle as the backend.Goal is to have 100% Flickr api coverage rather than just upload/display photos (currently at 23%).
统计信息
- 总下载量: 20
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-21