PHPackages                             concept-labs/http-message - 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. concept-labs/http-message

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

concept-labs/http-message
=========================

(C)oncept-Labs HTTP

1.1.1(6mo ago)0921MITPHPPHP &gt;=8.2

Since Aug 3Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/Concept-Labs/http-message)[ Packagist](https://packagist.org/packages/concept-labs/http-message)[ RSS](/packages/concept-labs-http-message/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (17)Used By (1)

HTTP Message
============

[](#http-message)

A PSR-7 and PSR-17 compliant HTTP Message implementation for PHP 8.2+. This library provides a complete set of HTTP message abstractions following the PHP-FIG standards, designed to work seamlessly with the Singularity Container ecosystem.

[![Tests](https://camo.githubusercontent.com/3ab4882a1b7d64e5eb5168ad0b0b9cdfd53f59f114ee5f727958504214a5789c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d70617373696e672d627269676874677265656e2e737667)](https://github.com/Concept-Labs/http-message)[![PHP Version](https://camo.githubusercontent.com/c5e8da782b1a0673c08b4f474108036d2cc973470eed2d5d89d48e8c8475eee6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e322d626c75652e737667)](https://www.php.net/)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)

Features
--------

[](#features)

- ✅ **PSR-7 Compliance**: Full implementation of HTTP message interfaces
- ✅ **PSR-17 Compliance**: Complete set of HTTP factories
- ✅ **Immutable Messages**: All message modifications return new instances
- ✅ **Stream Support**: Robust stream handling for request/response bodies
- ✅ **URI Handling**: Complete URI manipulation and validation
- ✅ **File Uploads**: PSR-7 compliant uploaded file handling
- ✅ **Server Requests**: Full server-side request support
- ✅ **Singularity Compatible**: Designed for the Singularity Container ecosystem
- ✅ **Fully Tested**: Comprehensive test coverage with PEST

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

[](#installation)

```
composer require concept-labs/http-message
```

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

[](#requirements)

- PHP 8.2 or higher
- PSR HTTP Message (psr/http-message)
- PSR HTTP Factory (psr/http-factory)
- Fig HTTP Message Utilities (fig/http-message-util)

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

[](#quick-start)

### Creating a Response

[](#creating-a-response)

```
use Concept\Http\Message\Response\ResponseFactory;
use Concept\Http\Message\Response\Response;
use Concept\Http\Message\Stream\StreamFactory;
use Concept\Http\Message\Stream\Stream;

// Create factories
$streamFactory = new StreamFactory(new Stream());
$responseFactory = new ResponseFactory(new Response(), $streamFactory);

// Create a response
$response = $responseFactory->createResponse(200, 'OK');
$response = $response->withHeader('Content-Type', 'application/json');
```

### Creating a Request

[](#creating-a-request)

```
use Concept\Http\Message\Request\RequestFactory;
use Concept\Http\Message\Request\Request;
use Concept\Http\Message\Uri\UriFactory;
use Concept\Http\Message\Uri\Uri;

// Create factories
$uriFactory = new UriFactory(new Uri());
$requestFactory = new RequestFactory($uriFactory, $streamFactory, new Request());

// Create a request
$request = $requestFactory->createRequest('GET', 'https://api.example.com/users');
$request = $request->withHeader('Accept', 'application/json');
```

### Working with URIs

[](#working-with-uris)

```
use Concept\Http\Message\Uri\Uri;

$uri = new Uri();
$uri = $uri->withScheme('https')
    ->withHost('example.com')
    ->withPath('/api/v1/users')
    ->withQuery('page=1&limit=10')
    ->withFragment('results');

echo $uri; // https://example.com/api/v1/users?page=1&limit=10#results
```

### Working with Streams

[](#working-with-streams)

```
use Concept\Http\Message\Stream\Stream;
use Concept\Http\Message\Stream\StreamFactory;

$streamFactory = new StreamFactory(new Stream());

// Create from string
$stream = $streamFactory->createStream('Hello, World!');

// Create from file
$stream = $streamFactory->createStreamFromFile('/path/to/file.txt');

// Create from resource
$resource = fopen('php://memory', 'r+');
$stream = $streamFactory->createStreamFromResource($resource);
```

Documentation
-------------

[](#documentation)

For detailed documentation, please refer to:

- [Getting Started](docs/getting-started.md)
- [HTTP Messages](docs/messages.md)
- [Streams](docs/streams.md)
- [URIs](docs/uris.md)
- [Factories](docs/factories.md)
- [Server Requests](docs/server-requests.md)
- [File Uploads](docs/file-uploads.md)
- [Singularity Integration](docs/singularity.md)

PSR-7 Components
----------------

[](#psr-7-components)

### Messages

[](#messages)

- `Message` - Base HTTP message implementation
- `Request` - HTTP request implementation
- `ServerRequest` - Server-side HTTP request
- `Response` - HTTP response implementation

### Streams

[](#streams)

- `Stream` - PSR-7 stream implementation
- `StreamFactory` - Creates stream instances

### URIs

[](#uris)

- `Uri` - URI implementation with validation
- `UriFactory` - Creates URI instances

### Uploaded Files

[](#uploaded-files)

- `UploadedFile` - Uploaded file representation
- `UploadedFileFactory` - Creates uploaded file instances
- `UploadedFileNormalizer` - Normalizes $\_FILES array

PSR-17 Factories
----------------

[](#psr-17-factories)

All factory implementations follow PSR-17:

- `RequestFactory` - Creates PSR-7 requests
- `ResponseFactory` - Creates PSR-7 responses
- `ServerRequestFactory` - Creates PSR-7 server requests
- `StreamFactory` - Creates PSR-7 streams
- `UploadedFileFactory` - Creates PSR-7 uploaded files
- `UriFactory` - Creates PSR-7 URIs

Singularity Container Integration
---------------------------------

[](#singularity-container-integration)

This library is designed to work with the [Singularity Container](https://github.com/Concept-Labs/singularity) ecosystem. The `concept.json` configuration file defines service bindings for automatic dependency injection.

Key integration features:

- **Shared Services**: Factories are marked as shared (singletons)
- **Prototype Services**: Message objects are prototypes (new instance per request)
- **Automatic Wiring**: Container automatically resolves dependencies

See [Singularity Integration](docs/singularity.md) for details.

Testing
-------

[](#testing)

The library includes comprehensive tests using PEST:

```
# Install dependencies
composer install

# Run tests
composer test

# Run tests with coverage
./vendor/bin/pest --coverage
```

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

[](#architecture)

### SOLID Principles

[](#solid-principles)

The library follows SOLID principles:

- **Single Responsibility**: Each class has a focused purpose
- **Open/Closed**: Extensible through inheritance and composition
- **Liskov Substitution**: All implementations properly extend base interfaces
- **Interface Segregation**: Small, focused interfaces
- **Dependency Inversion**: Depends on abstractions, not concretions

### Design Patterns

[](#design-patterns)

- **Factory Pattern**: PSR-17 factories for object creation
- **Prototype Pattern**: Message objects support cloning
- **Immutable Objects**: All message modifications return new instances
- **Dependency Injection**: Constructor-based dependency injection

Contributing
------------

[](#contributing)

Contributions are welcome! Please:

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests for new functionality
5. Ensure all tests pass
6. Submit a pull request

License
-------

[](#license)

This library is licensed under the MIT License. See [LICENSE](LICENSE) for details.

Credits
-------

[](#credits)

Developed by Viktor Halytskyi and the Concept Labs team.

Support
-------

[](#support)

- 📧 Email:
- 🐛 Issues: [GitHub Issues](https://github.com/Concept-Labs/http-message/issues)
- 📖 Documentation: [docs/](docs/)

Related Projects
----------------

[](#related-projects)

- [Singularity Container](https://github.com/Concept-Labs/singularity) - Dependency injection container
- [PSR-7](https://www.php-fig.org/psr/psr-7/) - HTTP message interfaces
- [PSR-17](https://www.php-fig.org/psr/psr-17/) - HTTP factories

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance66

Regular maintenance activity

Popularity9

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 81.3% 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

Every ~34 days

Recently: every ~21 days

Total

14

Last Release

197d ago

PHP version history (2 changes)1.0.0PHP ^7.2|^7.4|^8.0|^8.2

1.0.3.3PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/39bcfd110a5cc1f2d7ff687193670d00133cf415ad2b9959afaff24ff1e564fd?d=identicon)[vgalitsky](/maintainers/vgalitsky)

---

Top Contributors

[![vgalitsky](https://avatars.githubusercontent.com/u/1241206?v=4)](https://github.com/vgalitsky "vgalitsky (26 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (6 commits)")

---

Tags

httppsr-7http-messagephp

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/concept-labs-http-message/health.svg)

```
[![Health](https://phpackages.com/badges/concept-labs-http-message/health.svg)](https://phpackages.com/packages/concept-labs-http-message)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.0B3.1k](/packages/guzzlehttp-psr7)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

86874.0k94](/packages/httpsoft-http-message)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[mezzio/mezzio-authentication-oauth2

OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications.

28483.0k2](/packages/mezzio-mezzio-authentication-oauth2)[art4/requests-psr18-adapter

Use WordPress/Requests as a PSR-18 HTTP client

153.3k](/packages/art4-requests-psr18-adapter)[httpsoft/http-server-request

Infrastructure for creating PSR-7 ServerRequest and UploadedFile

15112.6k29](/packages/httpsoft-http-server-request)

PHPackages © 2026

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