wp-oop/http-client
Composer 安装命令:
composer require wp-oop/http-client
包简介
A PSR-18 wrapper for the WordPress HTTP API
README 文档
README
A PSR-18 wrapper for the WordPress HTTP API.
Usage
use Psr\Http\Client\ClientExceptionInterface; use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\ResponseFactoryInterface; use WpOop\HttpClient\Client; /** @var RequestFactoryInterface $requestFactory */ /** @var ResponseFactoryInterface $responseFactory */ // Set up the client with WP request options // https://developer.wordpress.org/reference/classes/wp_http/request/ $client = new Client( // Default args to WP_Http::request() [ 'redirection' => 2, 'timeout' => 60, ], $responseFactory, // Path to proxy file dir to enable response streaming. // If null, will buffer in memory instead. get_temp_dir() ); // Create a PSR-7 request in any way you want, for example via a PSR-17 factory $request = $requestFactory->createRequest('GET', 'http://somesite.com/api'); try { // Send a request as usual, consuming a familiar PSR-18 interface $response = $client->sendRequest($request); } catch (ClientExceptionInterface $e) { // Handle PSR-18 exceptions }
Since this is a PSR-18-compliant implementation, you can consume it in the way you would any other.
To set it up, pass a map of WP request options, and a PSR-17 response factory. This approach facilitates decoupling from any concrete PSR-7 implementation.
You can use any PSR-17 implementation or PSR-7 implementations. I suggest the slim and efficient nyholm/psr7, which conveniently implements both.
Limitations
Currently only throws ClientExceptionInterface, as it is unable to reliably determine whether a network or
another specific kind of problem has occurred from the error value returned by wp_remote_request().
wp-oop/http-client 适用场景与选型建议
wp-oop/http-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.94k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2023 年 08 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 wp-oop/http-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wp-oop/http-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.94k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-08-18