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

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

slendium/http
=============

A framework-agnostic library for interoperable HTTP messaging.

00PHP

Since Mar 13Pushed 2mo ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Slendium HTTP
=============

[](#slendium-http)

A framework-agnostic PHP library for handling HTTP. Includes:

- PHPDoc type annotations for static analyzers
- Common types related to HTTP, such as `Field`, `MediaType`, `Uri` and `IpAddress`
- Parsing and serialization of IPv4 and IPv6 addresses
- Parsing and serialization of structured fields per [RFC 9651](https://www.rfc-editor.org/rfc/rfc9651.html)

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

[](#installation)

Requires **PHP &gt;= 8.5**. Simply run `composer install slendium/http` to add it to your project. Most likely you do not want to use this package directly, but use the following implementation(s) instead:

- [slendium/http-superglobals](https://github.com/slendium/http-superglobals) - implements these interfaces directly using the PHP superglobal variables
- [slendium/http-client](https://github.com/slendium/http-client) - a cURL-based HTTP client implementation based on these interfaces

Examples
--------

[](#examples)

### Consume a request

[](#consume-a-request)

```
$networked = $framework->getRequest(); // returns a Networked
$request = $networked->payload; // the request message with headers, body and trailers
$address = $networked->address; // contain IP and port, can be passed around independently

// implementation-agnostic access to POST-ed data ($_POST, form data, JSON, CBOR, mocked data)
if ($request->body instanceof Structured) {
	$post = $request->body->root; // ArrayAccess&Countable&Traversable
}

// access query arguments
$queryData = $request->uri->getQuery(); // (ArrayAccess&Countable&Traversable)|null

// implementation-agnostic access to cookies (a parsed header, $_COOKIES or even mocked values)
if ($request->headers['cookie'] instanceof Structured) {
	$cookies = $request->headers['cookie']->root; // ArrayAccess&Countable&Traversable
	// or get the raw value instead
	$cookieString = $request->headers['cookie']->value;
}
```

### Uploaded files

[](#uploaded-files)

```
if ($request->body instanceof Structured) {
	// files are merged with body data
	$upload = $request->body->root['file'];
	if ($upload instanceof UploadedFile) {
		// process file
	} else if ($upload instanceof UploadFailure) {
		// handle error
	}
}
```

### Obtain structured values

[](#obtain-structured-values)

```
// check if implementation recognized the header
$field = $request->headers['x-custom-field'];
if ($field instanceof DictionaryField) {
	// do something with an RFC 9651 dictionary
	$dictionary = $field->toDictionary();
} else if ($field instanceof ListField) {
	// do something with an RFC 9651 list
	$list = $field->toList();
} else if ($field instanceof ItemField) {
	// do something with an RFC 9651 item
	$item = $field->toItem();
	if ($item instanceof Item\BinarySequence) { ... } // etc.
}
```

### Parse or serialize structured values

[](#parse-or-serialize-structured-values)

```
$value = $headers['x-custom-header']->value;

// parse strictly according to the spec
$strict = new Rfc9651Parser();
$asList = $strict->parseList($value);
$asDictionary = $strict->parseDictionary($value);
$asItem = $strict->parseItem($value);

// parse with higher error tolerance
$lenient = new LenientParser();
$asList = $lenient->parseList($value);
// ...etc

// serialize strictly according to the spec
$serializer = new Rfc9651Serializer();
echo $serializer->serializeItem(new Item\DisplayString('Hello')); // prints %"Hello"
```

### IP-addresses

[](#ip-addresses)

```
// create raw ip address from octets or 16-bit values and convert them to strings later
$ipv4 = IpAddress::V4([ 127, 0, 0, 1 ]);
echo (string)$ipv4, "\n";
$ipv6 = IpAddress::V6([ 0, 0, /* ... */ 0x80 ]);
echo (string)$ipv6, "\n";

// parse a string into ipv4 or ipv6
$parsed = IpAddress::fromString($addrString);
if ($parsed instanceof Ipv4Address) { ... }
else if ($parsed instanceof Ipv6Address { ... }
```

Motivation
----------

[](#motivation)

This library serves a similar purpose as [PSR-7](https://www.php-fig.org/psr/psr-7/), but the decision not to use PSR-7 was based on the following factors:

- The design has aged, many of the interface "getters" can be replaced by property hooks now
- The interfaces force implementation of a builder pattern - e.g. `withMethod()` - which requires implementing a lot of methods you don't need when you are simply responding to a single request received through PHP/CGI
- Some of the interfaces contain methods that could be folded into built-in PHP types: e.g. `hasHeader()`, `getHeader()`, `withHeader()`, `addHeader()`, `getHeaders()` could all be replaced using an `ArrayAccess&Traversable` type hint for a `$headers` property
- The PHP "superglobals" are not integrated transparently, they require a separate interface which `RequestInterface` consumers need to be aware of
- No abstractions for messages that contain structured objects - a message consumer should be able to treat input data generically without knowing the serialization method (form data, JSON, CBOR, ...)
- Missing interfaces for common HTTP concepts such as "fields", "media types", "structured values", etc.

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance57

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/f8cb32e80bc8745da0070b0df3e42a7a4d0de1064a34bd32eafc341437f2b193?d=identicon)[packagist.uch8@frisiapp.com](/maintainers/packagist.uch8@frisiapp.com)

---

Top Contributors

[![cfahner](https://avatars.githubusercontent.com/u/3216275?v=4)](https://github.com/cfahner "cfahner (100 commits)")

### Embed Badge

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

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

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78026.4M414](/packages/react-http)[php-http/curl-client

PSR-18 and HTTPlug Async client with cURL

48347.0M384](/packages/php-http-curl-client)[smi2/phpclickhouse

PHP ClickHouse Client

84310.1M71](/packages/smi2-phpclickhouse)

PHPackages © 2026

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