phprise / http
The HTTP Client component applying the OTAKU philosophy and following the PSR-12, PSR-7, PSR-15, PSR-18 e PSR-14.
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/phprise/http
Requires
- php: ^8.4
- php-http/httplug: ^2.4
- php-http/promise: ^1.3
- phprise/common-contract: ^1.0
- phprise/common-value-object: ^1.0
- phprise/data-transfer-object: ^1.1
- psr/event-dispatcher: ^1.0
- psr/http-client: ^1.0
- psr/http-factory: ^1.1
- psr/http-message: ^2.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- infection/infection: ^0.32.2
- phpunit/phpunit: ^12.5
- vimeo/psalm: ^6.14
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