phprise/http
最新稳定版本:v1.0.0
Composer 安装命令:
composer require phprise/http
包简介
The HTTP Client component applying the OTAKU philosophy and following the PSR-12, PSR-7, PSR-15, PSR-18 e PSR-14.
README 文档
README
The HTTP component applying the OTAKU philosophy and following the PSR-12, PSR-7, PSR-18, and PSR-14.
Installation
composer require phprise/http
Quick Start (Native Implementation)
PHPRise HTTP comes with a NativeClient based on PHP's cURL extension, allowing you to send requests without external weight (like Guzzle).
Synchronous Requests
use Phprise\Http\Connector; use Phprise\Http\Client\NativeClient; use Phprise\Http\Request\ListRequest; use Phprise\Http\ValueObject\Uri; $connector = new Connector(new NativeClient()); $request = new ListRequest(new Uri('https://jsonplaceholder.typicode.com/posts')); $response = $connector->send($request); echo $response->getStatusCode(); // 200
Asynchronous Requests
use Phprise\Http\AsyncConnector; use Phprise\Http\Client\NativeClient; $async = new AsyncConnector(new NativeClient()); $promise = $async->send($request); $promise->then(function ($response) { echo $response->getStatusCode(); }); $promise->wait();
Advanced Usage
1. The Connector
The Connector wraps any PSR-18 Client.
use Phprise\Http\Connector; $connector = new Connector($anyPsr18Client);
2. Semantic Requests
Requests are semantic-first and implement Psr\Http\Message\RequestInterface directly.
| Request Type | Method | Purpose |
|---|---|---|
ListRequest |
GET | List resources with query params. |
ShowRequest |
GET | Fetch a single resource. |
StoreRequest |
POST | Create a new resource with a DTO. |
UpdateRequest |
PATCH | Partial update with a DTO. |
ReplaceRequest |
PUT | Complete replacement with a DTO. |
DestroyRequest |
DELETE | Remove a resource. |
3. Data Transfer Objects (DTO)
Stateful requests (Store, Update, Replace) require a payload implementing Phprise\DataTransferObject\TransferObjectInterface.
use Phprise\Http\Request\StoreRequest; use Phprise\Http\ValueObject\Uri; $request = new StoreRequest(new Uri($url), $myDto);
4. Intercepting Responses (Events)
Use EventedConnector for PSR-14 event dispatching.
use Phprise\Http\EventedConnector; $connector = new EventedConnector($baseConnector, $eventDispatcher);
Philosophy
We follow The OTAKU Manifesto: Fluid Structure Design.
- O - Own your Discipline (Strict Typing)
- T - Tools for Composition (Deeply composed objects)
- A - Armor the Core (Business value over infra)
- K - Keep Infrastructure Silent (PSR-7 integration)
- U - Universal Language (Semantic constructors)
License
MIT License
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-08