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

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

effectra/http-message
=====================

The Effectra HTTP Message package.

v2.0.0(3w ago)07416MITPHPPHP ^8.0.2

Since Jul 24Pushed 2y agoCompare

[ Source](https://github.com/effectra/http-message)[ Packagist](https://packagist.org/packages/effectra/http-message)[ RSS](/packages/effectra-http-message/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (5)Dependencies (9)Versions (6)Used By (6)

Effectra HTTP Message
=====================

[](#effectra-http-message)

A PSR-7 HTTP message library for PHP 8.1+.

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

[](#installation)

```
composer require effectra/http-message
```

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

[](#requirements)

- PHP ^8.1
- psr/http-message ^1.1 || ^2.0

Package Features
----------------

[](#package-features)

- **PSR-7 compliant** — `Request`, `Response`, `ServerRequest`, `Uri`, `Stream`, `UploadedFile`, `Message`
- **Case-insensitive headers** — `hasHeader()`, `getHeader()`, `withHeader()`, etc. all normalize to lowercase
- **Immutable with\* methods** — all PSR-7 `with*` methods return new instances; mutable `set*` methods are also available
- **Response factories** — `withJson()`, `static json()`, `static html()`, `static emptyResponse()`
- **ServerRequest utilities** — `fromGlobals()` factory, `replaceHeader()` helper
- **Stream from file path** — constructor accepts a file path string and opens it as a resource
- **UploadedFile** — `getStream()` reads from the actual uploaded file
- **PHP 8 features** — `final` classes, `readonly` properties, `#[Immutable]` attribute
- **Comprehensive test suite** — 196+ tests, PHPStan level 6 clean

Usage
-----

[](#usage)

### Creating a Request

[](#creating-a-request)

```
use Effectra\Http\Message\Request;
use Effectra\Http\Message\Uri;

$uri = new Uri('https://api.example.com/users');
$request = new Request('POST', $uri, ['Content-Type' => 'application/json'], '{"name":"John"}');

echo $request->getMethod();                 // POST
echo $request->getHeaderLine('Content-Type'); // application/json
```

Immutable `with*` methods:

```
$new = $request->withMethod('PUT')->withUri(new Uri('https://other.com'));
// $request is unchanged
```

Mutable `set*` methods:

```
$request->setMethod('PATCH')->setUri(new Uri('/local'));
// $request is modified in place
```

### Creating a Response

[](#creating-a-response)

```
use Effectra\Http\Message\Response;

$response = new Response(200, ['X-Custom' => 'value'], 'OK');
echo $response->getStatusCode();              // 200
echo $response->getReasonPhrase();            // OK
```

#### Response Factories

[](#response-factories)

```
// JSON response
$res = Response::json(['status' => 'ok']);
$res = (new Response())->withJson(['error' => 'bad'], 400);

// HTML response
$res = Response::html('Hello', 200);

// Empty response (e.g. 204 No Content)
$res = Response::emptyResponse(204);
```

All standard HTTP status codes (100–511) are available as class constants:

```
Response::HTTP_OK;               // 200
Response::HTTP_NOT_FOUND;        // 404
Response::HTTP_I_AM_A_TEAPOT;    // 418
```

### ServerRequest (from globals)

[](#serverrequest-from-globals)

```
use Effectra\Http\Message\ServerRequest;

$request = ServerRequest::fromGlobals();

echo $request->getMethod();          // GET, POST, etc.
echo $request->getServerParams()['REMOTE_ADDR'];
$input = $request->getParsedBody();  // POST / JSON body
```

### Working with URIs

[](#working-with-uris)

```
use Effectra\Http\Message\Uri;

$uri = new Uri('https://example.com/path?q=hello#section');

echo $uri->getScheme();    // https
echo $uri->getHost();      // example.com
echo $uri->getPath();      // /path
echo $uri->getQuery();     // q=hello

$new = $uri->withScheme('http')->withHost('other.org');
```

### Stream

[](#stream)

```
use Effectra\Http\Message\Stream;

// From a string
$stream = new Stream('content');
echo $stream->getContents(); // content

// From a file path (opens automatically)
$stream = new Stream('/path/to/file.txt');

// From a resource
$stream = new Stream(fopen('php://memory', 'r+'));
$stream->write('data');
```

### Uploaded Files

[](#uploaded-files)

```
use Effectra\Http\Message\UploadedFile;

$file = new UploadedFile(
    $_FILES['avatar']['tmp_name'],
    $_FILES['avatar']['size'],
    $_FILES['avatar']['error'],
    $_FILES['avatar']['name'],
    $_FILES['avatar']['type']
);

$stream = $file->getStream();            // read file contents
echo $file->getClientFilename();         // original name
$file->moveTo('/storage/avatars/1.jpg');
```

### Case-Insensitive Headers

[](#case-insensitive-headers)

All header operations are case-insensitive:

```
$request = new Request('GET', '/', ['Content-Type' => 'text/html']);

$request->hasHeader('content-type');     // true
$request->hasHeader('CONTENT-TYPE');     // true
$request->hasHeader('Content-Type');     // true

$request->getHeader('CONTENT-TYPE');     // ['text/html']

$cloned = $request->withoutHeader('content-type');
$cloned = $request->withAddedHeader('X-Custom', 'val');
```

### Attributes (PHP 8)

[](#attributes-php-8)

```
use Effectra\Http\Message\Attribute\Immutable;

#[Immutable('This class follows the PSR-7 immutable pattern')]
class MyMessage
{
    // ...
}
```

`#[Immutable]` and `#[Deprecated]` attributes are available for documentation and static analysis.

PHPStan
-------

[](#phpstan)

```
composer run phpstan
```

Level 6 with baseline. The `_ide_helper.php` file provides additional type information for better IDE support.

Testing
-------

[](#testing)

```
composer test
```

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

[](#contributing)

Contributions are welcome. Please open an issue or submit a pull request.

License
-------

[](#license)

MIT

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance53

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity53

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

Every ~274 days

Total

5

Last Release

22d ago

Major Versions

v1.0.3 → v2.0.02026-07-26

### Community

Maintainers

![](https://www.gravatar.com/avatar/7e6219ae87e98df8783b2f595b013035dd183c0712afd24045a8acf0a40c3bdf?d=identicon)[effectra](/maintainers/effectra)

---

Top Contributors

[![BMTmohammedtaha](https://avatars.githubusercontent.com/u/95439605?v=4)](https://github.com/BMTmohammedtaha "BMTmohammedtaha (15 commits)")

---

Tags

httphttp-messagephppsrpsr-7requestresponseserver-requeststreamupload-fileuri

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.1B4.4k](/packages/guzzlehttp-psr7)[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.2k555.0M2.8k](/packages/aws-aws-sdk-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k832.6k55](/packages/neuron-core-neuron-ai)[tempest/framework

The PHP framework that gets out of your way.

2.3k37.6k21](/packages/tempest-framework)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

36826.2k2](/packages/telnyx-telnyx-php)[mimmi20/browser-detector

Library to detect Browsers and Devices

49158.4k5](/packages/mimmi20-browser-detector)

PHPackages © 2026

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