PHPackages                             ascetic-soft/psr7 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. ascetic-soft/psr7

ActiveLibrary[HTTP &amp; Networking](/categories/http)

ascetic-soft/psr7
=================

A lightweight, performance-optimized PSR-7 and PSR-17 implementation for PHP 8.4+

v1.0.0(3mo ago)06MITPHPPHP &gt;=8.4

Since Feb 17Pushed 3mo agoCompare

[ Source](https://github.com/ascetic-soft/Psr7)[ Packagist](https://packagist.org/packages/ascetic-soft/psr7)[ RSS](/packages/ascetic-soft-psr7/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

AsceticSoft PSR-7
=================

[](#asceticsoft-psr-7)

A lightweight, performance-optimized [PSR-7](https://www.php-fig.org/psr/psr-7/) (HTTP Messages) and [PSR-17](https://www.php-fig.org/psr/psr-17/) (HTTP Factories) implementation for PHP 8.4+.

Designed as a companion library for [Waypoint](https://github.com/ascetic-soft/Waypoint) router, but works with any PSR-7/PSR-15/PSR-17 compatible stack.

Features
--------

[](#features)

- **Full PSR-7 compliance** — implements all 7 interfaces from `psr/http-message` v2.0
- **Full PSR-17 compliance** — implements all 6 factory interfaces from `psr/http-factory` v1.0
- **Optimized headers** — O(1) case-insensitive lookups via dual-array storage
- **Lazy URI composition** — `__toString()` result cached, invalidated on mutation
- **Efficient immutability** — shallow `clone` with shared stream references
- **Thin stream wrapper** — minimal overhead over native PHP resources
- **ServerRequestCreator** — builds requests from `$_SERVER` / `$_GET` / `$_POST` / `$_COOKIE` / `$_FILES`
- **PHPStan level 9** — fully statically analyzed

Requirements
------------

[](#requirements)

- PHP &gt;= 8.4

Installation
------------

[](#installation)

```
composer require ascetic-soft/psr7
```

Quick Start
-----------

[](#quick-start)

```
use AsceticSoft\Psr7\HttpFactory;

$factory = new HttpFactory();

// Create a response
$response = $factory->createResponse(200);
$response->getBody()->write('Hello, World!');

// Create a request
$request = $factory->createRequest('GET', 'https://example.com/api/users');

// Create a URI
$uri = $factory->createUri('https://example.com/path?query=1#fragment');
```

Usage
-----

[](#usage)

### Creating HTTP Messages Directly

[](#creating-http-messages-directly)

```
use AsceticSoft\Psr7\Request;
use AsceticSoft\Psr7\Response;
use AsceticSoft\Psr7\ServerRequest;
use AsceticSoft\Psr7\Stream;
use AsceticSoft\Psr7\Uri;

// Request
$request = new Request('POST', 'https://api.example.com/users', [
    'Content-Type' => 'application/json',
    'Authorization' => 'Bearer token123',
], Stream::create(json_encode(['name' => 'John'])));

// Response
$response = new Response(200, ['Content-Type' => 'text/html']);

// Server Request
$serverRequest = new ServerRequest('GET', '/api/users', serverParams: $_SERVER);

// URI
$uri = new Uri('https://example.com:8080/path?q=1#frag');
echo $uri->getHost();   // "example.com"
echo $uri->getPort();   // 8080
echo $uri->getPath();   // "/path"
```

### Using the HttpFactory (PSR-17)

[](#using-the-httpfactory-psr-17)

The `HttpFactory` class implements all six PSR-17 factory interfaces in a single class:

```
use AsceticSoft\Psr7\HttpFactory;

$factory = new HttpFactory();

// RequestFactoryInterface
$request = $factory->createRequest('GET', '/path');

// ResponseFactoryInterface
$response = $factory->createResponse(404, 'Not Found');

// ServerRequestFactoryInterface
$serverRequest = $factory->createServerRequest('POST', '/api', $_SERVER);

// StreamFactoryInterface
$stream = $factory->createStream('content');
$fileStream = $factory->createStreamFromFile('/path/to/file', 'r');

// UriFactoryInterface
$uri = $factory->createUri('https://example.com');

// UploadedFileFactoryInterface
$uploadedFile = $factory->createUploadedFile($stream, 1024, UPLOAD_ERR_OK, 'file.txt');
```

### Creating Server Requests from Globals

[](#creating-server-requests-from-globals)

```
use AsceticSoft\Psr7\ServerRequestCreator;

// Create from PHP superglobals ($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES)
$request = ServerRequestCreator::fromGlobals();

// Or pass custom arrays
$request = ServerRequestCreator::fromGlobals(
    server: $_SERVER,
    get: $_GET,
    post: $_POST,
    cookies: $_COOKIE,
    files: $_FILES,
);
```

### Using with Waypoint Router

[](#using-with-waypoint-router)

```
use AsceticSoft\Psr7\ServerRequestCreator;
use AsceticSoft\Waypoint\Router;

$router = new Router($container);

$router->get('/hello/{name}', function (string $name) use ($factory) {
    $response = $factory->createResponse();
    $response->getBody()->write("Hello, {$name}!");
    return $response;
});

$request = ServerRequestCreator::fromGlobals();
$response = $router->handle($request);
```

Architecture
------------

[](#architecture)

```
AsceticSoft\Psr7\
├── Stream                — StreamInterface (thin resource wrapper)
├── Uri                   — UriInterface (lazy __toString, cached composition)
├── Request               — RequestInterface (uses MessageTrait)
├── Response              — ResponseInterface (const reason phrases)
├── ServerRequest         — ServerRequestInterface (extends Request)
├── UploadedFile          — UploadedFileInterface
├── HttpFactory           — All 6 PSR-17 factory interfaces
├── ServerRequestCreator  — Creates ServerRequest from PHP globals
└── MessageTrait          — Shared header/protocol/body logic (trait)

```

### Optimization Details

[](#optimization-details)

ComponentTechniqueBenefit**Headers**Dual-array: `$headers` (original case) + `$headerNames` (lowercase → original)O(1) case-insensitive lookup**Uri**Cached `__toString()`, invalidated on `with*()`Avoid recomposition on repeated access**Stream**Direct resource wrapper, pre-computed capabilitiesMinimal overhead, no unnecessary wrapping**Immutability**Shallow `clone`, shared stream referencesFast with\*() operations**Response**`const PHRASES` array for status codesZero-cost reason phrase lookupDevelopment
-----------

[](#development)

```
make fix       # Auto-fix code style (PHP CS Fixer)
make cs-check  # Check code style (dry-run)
make stan      # Run PHPStan static analysis (level 9)
make test      # Run PHPUnit tests
make check     # Run all checks (cs-check + stan + test)
make all       # Fix code style, then run stan and tests
```

License
-------

[](#license)

MIT

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance82

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

90d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/67126642d0e8ae8837b3104dcd120f7992ed0837538a7d140914e17420eb17c2?d=identicon)[borodulin](/maintainers/borodulin)

---

Top Contributors

[![borodulin](https://avatars.githubusercontent.com/u/8121448?v=4)](https://github.com/borodulin "borodulin (2 commits)")

---

Tags

httpresponserequestpsr-7streammessageuripsr-17

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ascetic-soft-psr7/health.svg)

```
[![Health](https://phpackages.com/badges/ascetic-soft-psr7/health.svg)](https://phpackages.com/packages/ascetic-soft-psr7)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.0B3.2k](/packages/guzzlehttp-psr7)[psr/http-factory

PSR-17: Common interfaces for PSR-7 HTTP message factories

1.9k692.9M1.9k](/packages/psr-http-factory)[pdeans/http

PSR-7 cURL HTTP client with support for PSR-17 HTTP factories.

1466.2k3](/packages/pdeans-http)[chillerlan/php-httpinterface

A PSR-7/17/18 http message/client implementation

1417.1k5](/packages/chillerlan-php-httpinterface)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[workerman/psr7

PSR-7 message implementation that also provides common utility methods

1079.8k10](/packages/workerman-psr7)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
