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
=============

Framework-agnostic library containing HTTP abstractions.

v0.2.0(1mo ago)051MITPHPPHP ^8.5

Since Apr 17Pushed 3mo ago1 watchersCompare

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

READMEChangelogDependencies (2)Versions (3)Used By (1)

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

36

—

LowBetter than 79% of packages

Maintenance83

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

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 ~18 days

Total

2

Last Release

58d ago

### 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)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### 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

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25126.1M82](/packages/php-http-cache-plugin)[illuminate/http

The Illuminate Http package.

11937.9M6.9k](/packages/illuminate-http)[rdkafka/rdkafka

A PHP extension for Kafka

2.2k24.3k1](/packages/rdkafka-rdkafka)[httpsoft/http-message

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

87965.9k114](/packages/httpsoft-http-message)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.4M91](/packages/mezzio-mezzio-router)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69127.2k](/packages/serpapi-google-search-results-php)

PHPackages © 2026

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