[■]
codesaur/http-message
1=[↕]
1:1 ══ composer require codesaur/http-message
codesaur/http-message · v3.0.4
HTTP Message
Clean, minimal, object-oriented HTTP Message component (PSR-7)
[■]
HTTP Message
A lightweight component implementing the HTTP message building blocks of PSR-7 - Request, Response, ServerRequest, URI, Stream, UploadedFile and OutputBuffer. It can be used standalone, independent of any framework.
Features
- Full PSR-7 MessageInterface, RequestInterface, ResponseInterface implementation
- ServerRequest - reconstructs the request from globals ($_SERVER, $_GET, $_POST, $_FILES)
- Uri - PSR-7 UriInterface with immutable with* methods
- Stream, Output - StreamInterface implementations with output buffering
- UploadedFile - uploaded file metadata + moveTo()
- NonBodyResponse - lightweight body-less response (fallback prototype)
- No external dependencies
Core classes
| Class | Purpose |
|---|---|
Message | PSR-7 MessageInterface implementation (headers, protocol, body) |
Request | PSR-7 RequestInterface |
Response | PSR-7 ResponseInterface |
ServerRequest | Reconstructs the request from the global environment |
Uri | PSR-7 UriInterface |
Stream | PSR-7 StreamInterface implementation |
UploadedFile | Uploaded file metadata + moveTo() |
Output | StreamInterface implementation (output buffering) |
Quick example
use codesaur\Http\Message\ServerRequest;
use codesaur\Http\Message\Response;
// ServerRequest үүсгэх / Create ServerRequest
$request = (new ServerRequest())->initFromGlobal();
// Query params
$query = $request->getQueryParams();
// PSR-7 headers унших / Read PSR-7 headers
$contentType = $request->getHeaderLine('Content-Type');
$csrfToken = $request->getHeaderLine('X-CSRF-TOKEN');
// Response үүсгэх / Create Response
$response = (new Response())
->withStatus(200)
->withHeader('Content-Type', 'application/json');
// Body-д бичих / Write to body
$response->getBody()->write(json_encode(['message' => 'Hello, World!']));
Running tests
composer test
[■]
Info
Install
composer require codesaur/http-message
Requirements
- PHP 8.2.1+
- ext-json
- Composer
Documentation