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

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

rammewerk/http
==============

A convenient way to handle HTTP requests and responses in PHP

0.1.0(1y ago)034MITPHPPHP &gt;=8.4

Since Feb 15Pushed 1y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

Rammewerk Http
==============

[](#rammewerk-http)

This package aims to provide a super easy starting point for building web applications, seamlessly integrating support for both traditional web requests and HTMX interactions.

It simplifies development with a clean, intuitive API, and offers type-safe input handling for requests and queries. A key feature is its powerful entity decoder, which leverages the fast and efficient Rammewerk Hydrator to effortlessly convert incoming requests into object entities. This allows for rapid development of data-driven applications with minimal boilerplate.

The package extends the Symfony HTTP Foundation components (`Request` and `Response`) with these added conveniences.

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

[](#installation)

To install the Rammewerk Request component, you can use Composer:

```
composer require rammewerk/http
```

Usage
-----

[](#usage)

Request
-------

[](#request)

The `Rammewerk\Http\Request` class extends the `Symfony Symfony\Component\HttpFoundation\Request` class. It provides several helper methods for working with requests, including **type-safe** input retrieval, **CSRF** token handling, and **entity hydration**.

### Initialization

[](#initialization)

The `RequestFactory` class provides a convenient way to create a new request instance.

```
use Rammewerk\Http\RequestFactory;
$request = RequestFactory::create();
```

To manually create a request instance without a session, use `RequestFactory::createWithoutSession()`. For more control, see the `Request` class and symfony documentation.

### Domain and URI Checks

[](#domain-and-uri-checks)

```
$path = $request->path(); // e.g., 'profile/settings'
$domain = $request->domainName(); // e.g., 'example.com'
$subdomain = $request->subdomain(); // e.g., 'api' from 'api.example.com'
$isSubdomain = $request->isSubdomain('api'); // true if subdomain is 'api'
```

### Input Retrieval

[](#input-retrieval)

The `input()` method retrieves input from the request body, query string, or uploaded files.

```
$name = $request->input('name'); // Get input from query or request body
$allInputs = $request->all(); // Get all inputs
$file = $request->file('avatar'); // Get uploaded file (returns Symfony\Component\HttpFoundation\File\UploadedFile)
```

### Type-Safe Input Retrieval

[](#type-safe-input-retrieval)

```
$name = $request->inputString('name'); // Get input as a string
$age = $request->inputInt('age'); // Get input as an integer
$price = $request->inputFloat('price'); // Get input as a float
$isActive = $request->inputBool('is_active'); // Get input as a boolean
$tags = $request->inputArray('tags'); // Get input as an array
$date = $request->inputDateTime('date', 'Y-m-d'); // Get input as a DateTimeImmutable object
$email = $request->inputEmail('email'); // Get input as a validated email string
```

### CSRF Token Handling

[](#csrf-token-handling)

```
$token = $request->generateCsrfToken(); // Generate a CSRF token
$request->validateCsrfToken(); // Validate the CSRF token from the request
```

### Entity Hydration

[](#entity-hydration)

```
use Rammewerk\Http\RequestFactory;
use App\Entity\User;

$request = RequestFactory::create();

// Simple hydration where each input key is mapped to an entity property
$user = $request->decode(User::class);

// More advanced hydration with custom mapping and required fields
$user = $request->decode(User::class, function (DecodeConfig $config) {
    $config->assign('first_name', 'firstName'); // Map request input 'first_name' to entity property 'firstName'
    $config->require('email'); // Mark 'email' as a required field
    $config->exclude('password'); // Exclude 'password' from being set
});

// $user is now an instance of App\Entity\User populated with data from the request
```

The `decode()` method hydrates an entity with data from the request. It supports mapping input keys to entity properties, specifying required fields, and excluding fields from being set. It uses the `Rammewerk\Component\Hydrator\Hydrator`component for the actual hydration process.

### Flash Messages

[](#flash-messages)

```
$request->flash('success', 'User created successfully!');
$messages = $request->getFlashMessages(); // Get all flash messages
```

### HTMX Helpers

[](#htmx-helpers)

```
$isHtmxRequest = $request->htmxRequest();
$currentUrl = $request->htmxCurrentUrl();
$historyRestoreRequest = $request->htmxHistoryRestoreRequest();
$promptResponse = $request->htmxPromptResponse();
$request = $request->htmxRequest();
$targetId = $request->htmxTargetId();
$triggerName = $request->htmxTriggerName();
$triggerId = $request->htmxTriggerId();
```

Response
--------

[](#response)

The `Rammewerk\Http\Response` class extends the `Symfony Symfony\Component\HttpFoundation\Response` class. It provides convenient methods for creating responses, especially for HTMX interactions.

### Basic Usage

[](#basic-usage)

```
use Rammewerk\Http\Response;
$response = new Response('Hello, world!');
$response->send();
```

### Redirects

[](#redirects)

```
$response = new Response();
$redirectResponse = $response->redirect('/dashboard');
$redirectResponse->send();
```

### HTMX Helpers

[](#htmx-helpers-1)

```
$response->htmxRedirect('/new-page');
$response->htmxRefresh();
$response->htmxLocation('/profile', ['userId' => 123]);
$response->htmxPushUrl('/new-url');
$response->htmxReplaceUrl('/old-url');
$response->htmxReswap('innerHTML');
$response->htmxRetarget('#target-element');
$response->htmxTriggers(['event1', 'event2']);
$response->htmxAfterSettleTriggers('afterSettleEvent');
$response->htmxAfterSwapTriggers(['afterSwap1', 'afterSwap2']);
```

### Page Not Found

[](#page-not-found)

A super simple static method for creating a 404 response.

```
use Rammewerk\Http\Response;
Response::pageNotFound('Page not found');
```

Contributing
------------

[](#contributing)

If you would like to contribute to the Rammewerk Request component, please feel free to submit a pull request. All contributions are welcome!

License
-------

[](#license)

Rammewerk Request is open-sourced software licensed under the MIT license.

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance40

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

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

Unknown

Total

1

Last Release

503d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/120019460?v=4)[RAMMEWERK](/maintainers/rammewerk)[@rammewerk](https://github.com/rammewerk)

---

Top Contributors

[![rammewerk](https://avatars.githubusercontent.com/u/120019460?v=4)](https://github.com/rammewerk "rammewerk (2 commits)")

---

Tags

htmxhttpphprequestrequestsresponsesymfonyrequest

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[symfony/security-bundle

Provides a tight integration of the Security component into the Symfony full-stack framework

2.5k185.6M2.4k](/packages/symfony-security-bundle)[symfony/http-kernel

Provides a structured process for converting a Request into a Response

8.1k869.4M8.8k](/packages/symfony-http-kernel)[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k51.2M339](/packages/api-platform-core)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.9M737](/packages/sylius-sylius)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.1k17.8k](/packages/prestashop-prestashop)[api-platform/http-cache

API Platform HttpCache component

274.6M20](/packages/api-platform-http-cache)

PHPackages © 2026

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