PHPackages                             joby/smol-request - 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. joby/smol-request

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

joby/smol-request
=================

A straightforward abstraction layer for retrieving information about and data from the current HTTP request.

v1.1.0(1mo ago)0170↓47.2%3MITPHPPHP &gt;=8.3CI passing

Since Jan 15Pushed 1mo agoCompare

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

READMEChangelog (6)Dependencies (8)Versions (7)Used By (3)

smolRequest
===========

[](#smolrequest)

A straightforward, type-safe abstraction layer for retrieving information about and data from the current HTTP request. Designed to minimize footguns, maximize productivity, and provide useful hinting and IntelliSense features in your IDE.

**Features:**

- Type-safe request data access with PHP enums and strongly-typed classes
- Built-in HTTP method enum (GET, HEAD, POST, PUT, DELETE, PATCH)
- Structured parsing of complex headers (Accept, Range, If-Modified-Since, If-None-Match, etc.)
- Type-safe cookie handling with validation
- POST data and file upload handling with built-in file type detection
- Request caching helpers with scope and key modifiers
- Requires PHP 8.3+

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

[](#installation)

```
composer require joby/smol-request
```

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

[](#quick-start)

All data about the current request can be accessed through `Request::current()`, and should be ready to go out of the box with no configuration on most servers.

```
use Joby\Smol\Request\Request;

// Get the current request
$request = Request::current();

// Type-safe URL access (via smol-url library)
$url = $request->url;
$host = $url->host;
$path = $url->path;

// HTTP method as enum
if ($request->method === \Joby\Smol\Request\Method::POST) {
    // Handle POST request
}

// Type-safe headers
if ($request->headers->has('accept')) {
    $accept = $request->headers->accept; // AcceptHeader
}

// Type-safe cookies
$sessionId = $request->cookies->get('PHPSESSID');

// Type-safe POST data
$email = $request->post->get('email');
$upload = $request->post->file('upload');

// Client source information
$clientIp = $request->source->client;  // Client IP from proxy (configurable trust settings)
$actualIp = $request->source->actual;  // Actual IP making request
```

Core Components
---------------

[](#core-components)

### Request (`Request`)

[](#request-request)

The main facade class providing access to all request data. Use `Request::current()` to get the current request.

**Properties:**

- `url`: URL object (from smolURL library)
- `method`: HTTP method enum
- `headers`: Structured header collection
- `cookies`: Cookie collection
- `post`: POST data and file uploads
- `source`: Client source information

### HTTP Method (`Method`)

[](#http-method-method)

An enum representing HTTP methods:

- `GET`
- `HEAD`
- `POST`
- `PUT`
- `DELETE`
- `PATCH`

### Headers (`Headers`)

[](#headers-headers)

Type-safe header handling with special parsing for common headers:

**Special Headers:**

- `accept` - Parsed `Accept` header with media types and quality values
- `range` - Parsed `Range` header with range specifications
- `if_modified_since` - Parsed `If-Modified-Since` header
- `if_none_match` - Parsed `If-None-Match` header (ETag)

**Generic Headers:**All other headers are available in the `generic` array.

```
// Check if header exists
if ($request->headers->has('x-custom-header')) {
    $header = $request->headers->get('x-custom-header');
}

// Access parsed headers
if ($request->headers->accept) {
    foreach ($request->headers->accept->media_types as $mediaType) {
        // $mediaType is AcceptHeaderMediaType
    }
}
```

### Cookies (`Cookies`)

[](#cookies-cookies)

Immutable cookie collection with automatic type normalization:

```
// Get a cookie value
$value = $request->cookies->get('name');

// Check if cookie exists
if ($request->cookies->has('session_id')) {
    $sessionId = $request->cookies->cookies['session_id'];
}

// All cookies as array
$allCookies = $request->cookies->cookies; // array
```

### POST Data (`Post`)

[](#post-data-post)

Structured access to POST form data and file uploads:

```
// Get form field
$name = $request->post->get('name', 'default value');

// Get required field (throws PostException if missing)
$email = $request->post->require('email');

// Get typed values
$age = $request->post->getInt('age');
$price = $request->post->getFloat('price');
$active = $request->post->getBool('active');

// Access uploaded files
$files = $request->post->files['profile_picture'] ?? [];
foreach ($files as $file) {
    // PostFile objects contain:
    // $file->filename: The base filename of the upload
    // $file->tmp_name: The temporary upload file location
    // $file->size: The size of the file in bytes
}

// All form values
$args = $request->post->args; // array
```

### Source (`Source`)

[](#source-source)

Information about the request source:

```
// Client IP (after proxy forwarding if applicable)
$clientIp = $request->source->client;

// Direct connection IP
$actualIp = $request->source->actual;
```

Advanced Usage
--------------

[](#advanced-usage)

### Request Caching Helpers

[](#request-caching-helpers)

Generate cache scopes and keys based on request characteristics:

```
// Get cache scope (affected by authorization, cookies, headers, session)
$scope = $request->cacheScope();

// Get cache key
$cacheKey = $request->cacheKey();
```

### Creating Modified Requests

[](#creating-modified-requests)

Create new request instances with modified properties:

```
// Create a new request with different method
$modified = $request->with(
    method: \Joby\Smol\Request\Method::POST
);

// All parameters are optional - only specified properties are replaced
$modified = $request->with(
    url: $newUrl,
    headers: $newHeaders,
    cookies: $newCookies,
);
```

### Custom Request Factories

[](#custom-request-factories)

Customize how requests are built from global state:

```
$factory = new \Joby\Smol\Request\RequestFactory();
// ... configure factory as needed

\Joby\Smol\Request\Request::setCurrentFactory($factory);
```

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

[](#requirements)

Fully tested on PHP 8.3+

License
-------

[](#license)

MIT License - See [LICENSE](LICENSE) file for details.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance90

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community10

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

Recently: every ~9 days

Total

6

Last Release

52d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f4e606aa41ebfd7d82c365c6dc4ec158fb1b0bfff5f8dcbfad4ab53e3092e6a6?d=identicon)[jobyone](/maintainers/jobyone)

---

Top Contributors

[![joby-lol](https://avatars.githubusercontent.com/u/856610?v=4)](https://github.com/joby-lol "joby-lol (8 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/joby-smol-request/health.svg)

```
[![Health](https://phpackages.com/badges/joby-smol-request/health.svg)](https://phpackages.com/packages/joby-smol-request)
```

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