jdwx/http-client
最新稳定版本:v1.1.0
Composer 安装命令:
composer require jdwx/http-client
包简介
A simple PHP module for HTTP clients.
README 文档
README
Module for PHP HTTP clients. Builds as much as possible off of PSR without introducing dependencies on any specific HTTP client implementation.
Installation
You can require it directly with Composer:
composer require jdwx/http-client
Or download the source from GitHub: https://github.com/jdwx/http-client.git
Requirements
This module requires PHP 8.3 or later.
Usage
This module doesn't really do anything on its own. It provides simple implementations of the PSR HTTP client interfaces, which can be useful for testing or for providing a base implementation that can be extended by other modules.
It also provides RequestDecorator and ResponseDecorator classes that can be used to modify requests and responses that implement RequestInterface and ResponseInterface respectively. This allows adding functionality without tying yourself to a specific HTTP client implementation.
The best usage example is the Response class, which inherits ResponseDecorator and adds some commonly-used functionality for working with HTTP responses.
Here is a basic usage example of using the Response class:
use JDWX\HttpClient\Response; $client = new \Some\Http\Client(); $response = $client->request('GET', 'https://api.example.com/resource'); $httpResponse = new Response($response); if (!$httpResponse->isSuccess()) { $statusCode = $httpResponse->getStatusCode(); echo "Error: HTTP Status {$statusCode}\n"; exit(1); } if (!$httpResponse->isContentType('application/json')) { echo "Error: Expected JSON response, got: " . $httpResponse->getContentType() . "\n"; exit(1); } $data = json_decode( $httpResponse->body(), true ); var_dump( $data );
Stability
This module is designed to stick as closely as possible to the PSR HTTP client interfaces, so it should be fairly stable. Additional functionality may be somewhat more likely to evolve over time as more use cases are encountered.
History
This module was refactored out of code adapted from the jdwx/json-api-client module in early 2025 and then extensively modified to conform to various PSR interfaces wherever possible.
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-28