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

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

horizom/http
============

The Horizom Http package.

5.2.1(2mo ago)02482MITPHPPHP ^8.0

Since Jul 10Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/horizom/http)[ Packagist](https://packagist.org/packages/horizom/http)[ Docs](https://horizom.github.io)[ RSS](/packages/horizom-http/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (13)Versions (14)Used By (2)

horizom/http
============

[](#horizomhttp)

[![Total Downloads](https://camo.githubusercontent.com/fb550766cad7c3d72954e4c0896077901bb83e851e0b4f7659416b2bacd359a5/68747470733a2f2f706f7365722e707567782e6f72672f686f72697a6f6d2f687474702f642f746f74616c2e737667)](https://packagist.org/packages/horizom/http)[![Latest Stable Version](https://camo.githubusercontent.com/b2050f7024e1c8d6471d29bdd512ab77c351118672eb05f2a9a639ba01ec2e2d/68747470733a2f2f706f7365722e707567782e6f72672f686f72697a6f6d2f687474702f762f737461626c652e737667)](https://packagist.org/packages/horizom/http)[![License](https://camo.githubusercontent.com/dd88fdc6f3a1372718a46689e5288f41aed9a498dadb931f06089f5e3d6f6008/68747470733a2f2f706f7365722e707567782e6f72672f686f72697a6f6d2f687474702f6c6963656e73652e737667)](https://packagist.org/packages/horizom/http)

A PSR-7 HTTP abstraction layer for PHP 8.0+, built on top of [Nyholm/PSR7](https://github.com/Nyholm/psr7) and [Symfony HttpFoundation](https://symfony.com/doc/current/components/http_foundation.html). Provides a rich, expressive API for working with HTTP requests, responses, URIs, streams, and file uploads.

---

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

[](#requirements)

- PHP 8.0 or higher
- Composer

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

[](#installation)

```
composer require horizom/http
```

---

Features
--------

[](#features)

- **Request** — PSR-7 server request with helpers for IP, headers, bearer tokens, content negotiation, URL building, and more.
- **Response** — Fluent PSR-7 response with JSON, redirect, file, and download helpers.
- **Uri** — Immutable URI value object.
- **Stream** — PSR-7 stream wrapper.
- **UploadedFile** — Symfony-backed uploaded file with extension guessing and hashed names.
- **Collections** — Type-safe parameter bags for query, body, server, and file data.
- **Exceptions** — Domain-specific HTTP and file exceptions.

---

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

[](#quick-start)

### Request

[](#request)

```
use Horizom\Http\Request;

$request = Request::capture(); // Builds from PHP superglobals

// Basic accessors
$request->method();            // 'GET'
$request->path();              // '/users/42'
$request->url();               // 'https://example.com/users/42'
$request->fullUrl();           // 'https://example.com/users/42?page=1'
$request->ip();                // '203.0.113.5'
$request->userAgent();         // 'Mozilla/5.0 ...'
$request->bearerToken();       // 'eyJ...' or null

// Security
$request->isSecure();          // true for HTTPS
$request->isMethod('POST');    // true / false (case-insensitive)

// Content negotiation
$request->isJson();            // Content-Type: application/json
$request->wantsJson();         // Accept: application/json
$request->ajax();              // X-Requested-With: XMLHttpRequest
$request->pjax();              // X-PJAX header present

// URL helpers
$request->setBasePath('/app');
$request->basePath();          // '/app'
$request->baseUrl();           // 'https://example.com/app'
$request->root();              // 'https://example.com'
$request->is('/admin/*');      // wildcard path matching
```

### Request Input

[](#request-input)

```
// Read input (query string, JSON body, form data)
$request->input('name');                    // single value
$request->input('name', 'default');        // with default
$request->all();                            // all input as array
$request->collect();                        // as Collection

// Typed accessors
$request->string('title');                 // string
$request->integer('page');                 // int
$request->float('price');                  // float
$request->boolean('active');              // bool

// Presence checks
$request->has('email');                    // true if key exists and non-null
$request->missing('token');               // true if key absent

// Filtering
$request->only('name', 'email');           // Collection with only these keys
$request->except('password');              // Collection without these keys

// Query string
$request->query('sort', 'name');

// Cookies and server params
$request->cookie('session_id');
$request->server('SERVER_NAME');

// File uploads
$request->hasFile('avatar');
$request->files('avatar');                 // UploadedFile or null
```

### Response

[](#response)

```
use Horizom\Http\Response;

// JSON response
$response = (new Response())->json(['user' => 'Alice'], 200);

// Redirect
$response = (new Response())->redirect('/dashboard');
$response = (new Response())->redirect('/login', 301);

// File delivery
$response = (new Response())->file('/var/www/storage/report.pdf');

// File download
$response = (new Response())->download('/var/www/storage/report.pdf', 'report.pdf');

// Using the helper function
$response = response()->json(['status' => 'ok']);
$response = redirect('/home');
```

#### PSR-7 Immutability

[](#psr-7-immutability)

`Response` is immutable — all mutating methods return a **new** instance:

```
$original = new Response(200);
$updated  = $original->json(['ok' => true]); // $original is unchanged
```

### Uri

[](#uri)

```
use Horizom\Http\Uri;

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

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

// Immutable modification
$newUri = $uri->withHost('other.com')->withPath('/new');
```

### Stream

[](#stream)

```
use Horizom\Http\Stream;

$stream = Stream::create('Hello, world!');
$stream->read(5);      // 'Hello'
$stream->getContents(); // ', world!'
```

### UploadedFile

[](#uploadedfile)

```
/** @var \Horizom\Http\UploadedFile $file */
$file = $request->files('avatar');

$file->get();                    // raw file contents (string)
$file->extension();              // guessed extension from MIME type
$file->clientExtension();        // guessed from the client-provided MIME
$file->hashName();               // '3d2f...a1b2.jpg'
$file->hashName('/uploads');     // '/uploads/3d2f...a1b2.jpg'
$file->path();                   // absolute path to the temp file

// Move to final location (Symfony UploadedFile API)
$file->move('/var/www/storage', $file->hashName());
```

### Collections

[](#collections)

#### `Collection` (generic parameter bag)

[](#collection-generic-parameter-bag)

```
use Horizom\Http\Collection\Collection;

$col = new Collection(['name' => 'Alice', 'age' => '30', 'tags' => ['php', 'http']]);

$col->get('name');              // 'Alice'
$col->get('missing', 'n/a');   // 'n/a'
$col->getInt('age');            // 30
$col->getBoolean('active');     // false (missing → false)
$col->getAlpha('slug');         // strips non-alpha characters
$col->getAlnum('code');         // strips non-alphanumeric characters
$col->getDigits('ref');         // strips non-digit characters
$col->all();                    // ['name' => 'Alice', 'age' => '30', ...]
$col->all('tags');              // ['php', 'http']
$col->keys();                   // ['name', 'age', 'tags']
$col->has('name');              // true
$col->remove('name');
$col->set('email', 'a@b.com');
$col->filter('email', null, FILTER_VALIDATE_EMAIL);
```

#### `ServerCollection`

[](#servercollection)

Parses `$_SERVER` superglobal and exposes HTTP headers:

```
use Horizom\Http\Collection\ServerCollection;

$server  = new ServerCollection($_SERVER);
$headers = $server->getHeaders(); // ['HOST' => 'example.com', 'ACCEPT' => '...', ...]
```

#### `FileCollection`

[](#filecollection)

Normalises PHP's inconsistent `$_FILES` format:

```
use Horizom\Http\Collection\FileCollection;

$files = new FileCollection($_FILES);
$file  = $files->get('avatar'); // UploadedFile | null
```

---

Exceptions
----------

[](#exceptions)

ExceptionWhen thrown`HttpException`General HTTP error (wraps status code)`BadRequestException`Malformed or unexpected request data`FileNotFoundException`File does not exist or cannot be read`FileExistsException`Target file already exists---

API Reference
-------------

[](#api-reference)

### `Request`

[](#request-1)

MethodReturnsDescription`create(string $uri, ...)``static`Static factory`capture()``static`Build from PHP superglobals`method()``string`HTTP verb`isMethod(string $method)``bool`Case-insensitive method check`path()``string`URI path`url()``string`URL without query string`fullUrl()``string`Full URL with query string`root()``string`Scheme + host`baseUrl()``string`root + basePath`basePath()``string`Configured base path`setBasePath(string $path)``void`Set base path`ip()``?string`Client IP (CF, X-Forwarded-For, REMOTE\_ADDR)`userAgent()``?string`User-Agent header`bearerToken()``?string`Bearer token from Authorization header`header(string $key, ...)``?string`Single header value`headers()``array`All headers`isSecure()``bool`HTTPS check`isJson()``bool`Content-Type is JSON`isHtml()``bool`Content-Type is HTML`wantsJson()``bool`Accept prefers JSON`ajax()``bool`XMLHttpRequest`pjax()``bool`PJAX request`is(string ...$patterns)``bool`Path wildcard match`fingerprint()``string`SHA1 request fingerprint`input(string $key, ...)``mixed`Input from any source`all()``array`All input`collect()``Collection`Input as collection`has(string $key)``bool`Key present and non-null`missing(string $key)``bool`Key absent`only(string ...$keys)``Collection`Subset of input`except(string ...$keys)``Collection`Input minus specified keys`hasFile(string $key)``bool`Uploaded file present`files(string $key)``UploadedFile|null`Uploaded file### `Response`

[](#response-1)

MethodReturnsDescription`create(int $status, ...)``static`Static factory`fromInstance(ResponseInterface $r)``static`Copy from existing response`json(mixed $data, ?int $status, ...)``static`JSON response`redirect(string $url, ?int $status)``static`Redirect response`redirectWithBaseUrl(?string $url, ...)``static`Redirect prepending base URL`setBaseUrl(string $url)``static`Set base URL for redirects`file(string|resource|StreamInterface $file)``static`Serve file body`download(string $path, ?string $name)``static`Force download`view(string $path, array $data)``static`Render PHP view template---

Testing
-------

[](#testing)

```
composer install
vendor/bin/phpunit
```

---

License
-------

[](#license)

MIT — see [LICENSE.md](LICENSE.md).

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance86

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Recently: every ~161 days

Total

13

Last Release

74d ago

Major Versions

3.1.3 → 5.0.02024-03-09

### Community

Maintainers

![](https://www.gravatar.com/avatar/412f8e786e65f078584b4bc2c0b7a44af095ab2c0d19a5fb7985598576ca4fda?d=identicon)[lambirou](/maintainers/lambirou)

---

Top Contributors

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

---

Tags

httpphppsr-7requestresponsehttpresponserequestphpfilehorizonhorizom

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[moonshine/moonshine

Laravel administration panel

1.3k253.1k81](/packages/moonshine-moonshine)[laravel/framework

The Laravel Framework.

34.8k543.8M20.1k](/packages/laravel-framework)[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.1B4.0k](/packages/guzzlehttp-psr7)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M572](/packages/shopware-core)[illuminate/http

The Illuminate Http package.

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

PHPackages © 2026

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