HTTP
Raxos HTTP provides the low level building blocks that the router and other packages build on. It wraps the incoming request in an immutable HttpRequest value object, exposes a family of typed HttpResponse classes for JSON, HTML, redirects, files and binary output, ships an outgoing HttpClient built on Guzzle with a PSR-18 and PSR-17 bridge, and includes an attribute driven validator that converts raw arrays into typed, validated request model objects.
Highlights
HttpRequestAn immutable, cached wrapper around the incoming request built from the PHP superglobals.HttpResponseA typed response hierarchy for JSON, HTML, redirects, files and binary output.HttpValidatorTurn raw arrays into validated, typed request model objects with attributes.HttpClientA fluent outgoing HTTP client built on Guzzle with a PSR-18 bridge.HttpMethodThe HTTP verbs used throughout the router and client as a backed enum.HttpResponseCodeEvery standard status code from 100 to 511, with reason phrases.Explore by category
- Requests and responses: build a request from the superglobals and return typed responses.
- Headers and status codes: the
HttpHeaderconstants, theHttpResponseCodeenum and the structure maps. - Request validation: attribute based request models, the
#[Property]attribute and constraint attributes. - HTTP client: the fluent outgoing client, its response wrapper and the PSR bridge.
Quick example
php
<?php
declare(strict_types=1);
use Raxos\Http\HttpRequest;
use Raxos\Http\Response\JsonHttpResponse;
use Raxos\Http\HttpResponseCode;
$request = HttpRequest::createFromGlobals();
$response = new JsonHttpResponse(
body: ['language' => $request->language()],
responseCode: HttpResponseCode::OK
);
$response->send();Installation
Install the package with Composer. See installation for the required PHP version and extensions.
shell
composer require raxos/http