PHPackages                             codemonster-ru/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. [Framework](/categories/framework)
4. /
5. codemonster-ru/http

ActiveLibrary[Framework](/categories/framework)

codemonster-ru/http
===================

Lightweight object-oriented HTTP foundation for PHP.

v2.0.0(4mo ago)11603MITPHPPHP &gt;=8.2CI passing

Since Oct 23Pushed 4mo agoCompare

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

READMEChangelog (2)Dependencies (1)Versions (3)Used By (3)

codemonster-ru/http
===================

[](#codemonster-ruhttp)

[![Latest Version on Packagist](https://camo.githubusercontent.com/cb63ac0d429ef60381e1baf4fb723fe494390d7eab072cdee4d45f5eb3ef603e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f64656d6f6e737465722d72752f687474702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/codemonster-ru/http)[![Total Downloads](https://camo.githubusercontent.com/29144e4716091f86d79a7dfdf9d91a64184b4e84c62270614ffdd51febe1fd34/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f64656d6f6e737465722d72752f687474702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/codemonster-ru/http)[![License](https://camo.githubusercontent.com/2164efa6b8827f2d14ca03ee042ceeeefdefb7463f1317b40d91f54ad25e93c7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f636f64656d6f6e737465722d72752f687474702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/codemonster-ru/http)[![Tests](https://github.com/codemonster-ru/http/actions/workflows/tests.yml/badge.svg)](https://github.com/codemonster-ru/http/actions/workflows/tests.yml)

Lightweight object-oriented HTTP foundation for PHP.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
- [Design Goals](#design-goals)
- [API Reference (Highlights)](#api-reference-highlights)
- [Edge Cases](#edge-cases)
- [Testing](#testing)
- [Migration Notes](#migration-notes)
- [Author](#author)
- [License](#license)

Design Goals
------------

[](#design-goals)

- Simple, small HTTP layer for frameworks or microservices.
- Predictable, test-friendly API with immutable helpers.
- Safe defaults for headers, cookies, and proxy handling.

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

[](#installation)

```
composer require codemonster-ru/http
```

Usage
-----

[](#usage)

### Handling HTTP Requests

[](#handling-http-requests)

```
use Codemonster\Http\Request;

// Capture the current request from PHP globals
$request = Request::capture();

echo $request->method();      // GET
echo $request->uri();         // /hello
echo $request->query('id');   // 42
echo $request->input('name'); // Vasya
```

You can also create a request manually (useful for tests or CLI):

```
$request = new Request(
    'POST',
    '/api/user',
    ['page' => 2],
    ['name' => 'John'],
    ['Accept' => 'application/json']
);

if ($request->wantsJson()) {
    // Return JSON
}
```

Request data helpers:

```
// input() excludes files, files() returns normalized uploads
$name = $request->input('name');
$files = $request->files();

// all() merges query + body + files
$all = $request->all();

// headers/server access
$headers = $request->headers();
$server = $request->server();

// full URL with query string
$url = $request->fullUrlWithQuery();

// immutable request changes
$request2 = $request
    ->withHeader('X-Trace', '1')
    ->withoutHeader('X-Deprecated')
    ->withQuery(['page' => 2])
    ->withInput(['name' => 'Vasya']);

// files with nested keys
$avatarName = $request->files('attachments.docs.a.name');
```

Trusted proxies:

```
// Trust proxy IPs (exact or CIDR) for ip() and isSecure()
Request::setTrustedProxies(['192.168.1.0/24', '2001:db8::/32']);

$ip = $request->ip();
$secure = $request->isSecure();
$ua = $request->userAgent();
```

Security note:

Only set trusted proxies if you control them. Otherwise, `X-Forwarded-*` headers can be spoofed and `ip()/isSecure()` will be incorrect.

Method override:

```
// For POST forms, override method via header or _method field
$_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'PATCH';
$_POST['_method'] = 'PUT';
```

Middleware-style response sending:

```
$request = Request::capture();
$response = $next($request);

// Respects HEAD automatically
$response->sendFor($request);
```

### Sending HTTP Responses

[](#sending-http-responses)

```
use Codemonster\Http\Response;

// Basic response
$response = new Response('Hello world', 200);
$response->send();

// JSON response with custom json_encode flags
return Response::json(['ok' => true], 200, [], JSON_UNESCAPED_SLASHES)->send();

// Redirect
return Response::redirect('/login');

// HEAD response (skip body)
$request = Request::capture();
(new Response('Hello'))->sendFor($request);

// Or send HEAD explicitly
(new Response('Hello'))->sendHead();

// Cookies (immutable)
$response = (new Response('OK'))
    ->withCookie('session', 'abc', ['path' => '/', 'httponly' => true])
    ->send();

// Cookie with options
(new Response('OK'))
    ->cookie('remember', '1', ['max_age' => 3600, 'samesite' => 'lax'])
    ->send();

// Cookies (mutable)
(new Response('OK'))
    ->cookie('session', 'abc')
    ->send();

// Multiple Set-Cookie via header array
(new Response('OK'))
    ->header('Set-Cookie', ['a=1', 'b=2'])
    ->send();

// SameSite=None forces Secure
(new Response('OK'))
    ->cookie('session', 'abc', ['samesite' => 'none'])
    ->send();

// Custom headers
$response = (new Response('Created', 201))
    ->header('X-Custom', '1')
    ->type('text/plain')
    ->send();

// Immutable response changes
$response = (new Response('OK', 200))
    ->withStatus(201)
    ->withHeader('X-Trace', '1')
    ->withType('text/plain')
    ->withHeaders(['X-Foo' => 'bar'])
    ->withoutHeader('X-Deprecated')
    ->withoutHeaders();
```

Convenience helpers:

```
// Filter input data
$only = $request->only(['name', 'email']);
$except = $request->except(['password']);

// Dot-notation for nested data
$onlyNested = $request->only(['user.name']);
$exceptNested = $request->except(['user.password']);

// Dot-notation for input/query
$name = $request->input('user.name');
$page = $request->query('meta.page');

// Dot-notation for files
$fileName = $request->files('attachments.docs.a.name');
```

API Reference (Highlights)
--------------------------

[](#api-reference-highlights)

Request:

- `Request::capture()`
- `method()`, `uri()`, `fullUrl()`, `fullUrlWithQuery()`
- `query()`, `input()`, `files()`, `all()`, `body()`
- `headers()`, `server()`, `header()`
- `only()`, `except()` (dot-notation supported)
- `ip()`, `isSecure()`, `userAgent()`
- `withHeader()`, `withoutHeader()`, `withQuery()`, `withInput()`
- `setTrustedProxies()` / `getTrustedProxies()`

Response:

- `send()`, `sendFor()`, `sendHead()`
- `json()`, `redirect()`, `empty()`, `type()`
- `header()`, `withHeader()`, `withHeaders()`, `withoutHeader()`, `withoutHeaders()`
- `withStatus()`, `withType()`
- `withCookie()`, `withoutCookie()`, `cookie()`

Edge Cases
----------

[](#edge-cases)

```
// 204/304 responses never send a body
(new Response('Will not be sent', 204))->send();

// If headers were already sent, an exception is thrown
// (guarded by headers_sent()).
```

Testing
-------

[](#testing)

You can run tests with the command:

```
composer test
```

Author
------

[](#author)

[**Kirill Kolesnikov**](https://github.com/KolesnikovKirill)

License
-------

[](#license)

[MIT](https://github.com/codemonster-ru/http/blob/main/LICENSE)

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance74

Regular maintenance activity

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity49

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

Total

2

Last Release

145d ago

Major Versions

v1.0.0 → v2.0.02025-12-24

### Community

Maintainers

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

---

Top Contributors

[![KolesnikovKirill](https://avatars.githubusercontent.com/u/33142935?v=4)](https://github.com/KolesnikovKirill "KolesnikovKirill (3 commits)")

---

Tags

frameworkhttpjsonphpredirectrequestresponsehttpresponserequestphpjsonframeworkredirect

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[php-curl-class/php-curl-class

PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs.

3.3k9.5M353](/packages/php-curl-class-php-curl-class)[davidepastore/slim-config

A slim middleware to read configuration from different files based on hassankhan/config

338.9k1](/packages/davidepastore-slim-config)

PHPackages © 2026

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