Skip to content

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

Explore by category

  • Requests and responses: build a request from the superglobals and return typed responses.
  • Headers and status codes: the HttpHeader constants, the HttpResponseCode enum 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