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

ActiveLibrary[Framework](/categories/framework)

fastpress/request
=================

A powerful and flexible HTTP request handling library for PHP, optimized for use with the Fastpress framework. Provides an easy-to-use interface for accessing request data and handling common request operations.

0.1.3(1y ago)0651MITPHPPHP ^7.4 || ^8.0

Since Feb 13Pushed 1y ago1 watchersCompare

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

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

Fastpress HTTP Request
======================

[](#fastpress-http-request)

This repository contains the `Request` class, a crucial component of the `fastpress/framework`. The `Request` class provides a comprehensive interface for handling HTTP requests in PHP applications. It simplifies accessing request data such as GET, POST, COOKIE, and SERVER variables, and includes methods for common request operations.

Features
--------

[](#features)

- Easy retrieval of GET, POST, COOKIE, and SERVER data.
- Convenience methods for checking the HTTP request method (GET, POST, PUT, DELETE).
- Utilities for common tasks like checking for Ajax requests and secure connections.
- Flexibility to extend or modify for custom use-cases.

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

[](#installation)

To use this component, first ensure you have `fastpress/framework` installed. This `Request` class is a dependency of the framework and is meant to be used within its context.

If you are managing your project with Composer, you can add this dependency directly by running:

```
composer require fastpress/request
```

Ensure that this aligns with the version constraints of fastpress/framework.

Usage
-----

[](#usage)

To use the Request class, create an instance of it in your PHP application:

```
use Fastpress\Http\Request;

$request = new Request();
```

Methods
-------

[](#methods)

### `validateCsrf(): bool`

[](#validatecsrf-bool)

Validates the CSRF token.

```
$isValid = $request->validateCsrf();
```

- Returns: true if the CSRF token is valid, otherwise throws a RuntimeException.

```
generateCsrfToken(): string
```

- Generates a new CSRF token and stores it in the session.

```
$token = $request->generateCsrfToken();
```

Returns: The generated CSRF token.

### `input(string $key, mixed $default = null, bool $sanitize = true): mixed`

[](#inputstring-key-mixed-default--null-bool-sanitize--true-mixed)

Retrieves an input value from GET, POST, or JSON data.

```
$name = $request->input('name');
$age = $request->input('age', 25);
$rawInput = $request->input('comment', null, false);
```

$key: The input key. $default: Optional. The default value to return if the key is not found. $sanitize: Optional. Whether to sanitize the value. Defaults to true. Returns: The input value.

### `file(string $key): ?array`

[](#filestring-key-array)

Retrieves an uploaded file.

```
$uploadedFile = $request->file('image');
```

$key: The file key. Returns: An array containing file information, or null if the file is not found.

```
hasFile(string $key): bool
```

Checks if an uploaded file exists and was uploaded successfully.

```
if ($request->hasFile('document')) {
  // Process the file
}
```

$key: The file key. Returns: true if the file exists and was uploaded successfully, false otherwise.

### `isJson(): bool`

[](#isjson-bool)

Checks if the request content type is JSON.

```
if ($request->isJson()) {
  // Process the JSON data
}
```

Returns: true if the content type is JSON, false otherwise. getMethod(): string Gets the HTTP request method.

```
$method = $request->getMethod();
```

Returns: The HTTP request method. getIp(): ?string Gets the client's IP address.

```
$ipAddress = $request->getIp();
```

Returns: The client's IP address, or null if it cannot be determined. accepts(string $contentType): bool Checks if the client accepts the given content type.

```
if ($request->accepts('application/json')) {
  // Send JSON response
}
```

$contentType: The content type to check. Returns: true if the client accepts the content type, false otherwise. header(string $key, mixed $default = null): mixed Retrieves a header value.

PHP $authToken = $request-&gt;header('Authorization');

```

$key: The header key.
$default: Optional. The default value to return if the header is not found.
Returns: The header value.
get(string $key, mixed $default = null): mixed
Retrieves a GET parameter.

```php
$page = $request->get('page', 1);

```

$key: The GET parameter key. $default: Optional. The default value to return if the key is not found. Returns: The GET parameter value. post(string $key, mixed $default = null): mixed Retrieves a POST parameter.

```
$email = $request->post('email');
```

$key: The POST parameter key. $default: Optional. The default value to return if the key is not found. Returns: The POST parameter value. json(string $key, mixed $default = null): mixed Retrieves a value from the parsed JSON request body.

```
$userId = $request->json('user_id');
```

$key: The JSON key. $default: Optional. The default value to return if the key is not found. Returns: The JSON value. getBody(): string Gets the raw request body.

```
$requestBody = $request->getBody();
```

Returns: The raw request body. validate(array $rules): array Validates the request data against the given rules.

```
$rules = [
  'name' => 'required|min:3',
  'email' => 'required|email',
];

$errors = $request->validate($rules);

if (!empty($errors)) {
  // Handle validation errors
}
```

$rules: An array of validation rules. Returns: An array of validation errors. setUrlParams(array $params): void Sets the URL parameters.

```
$request->setUrlParams(['id' => 10, 'slug' => 'my-article']);
```

$params: An array of URL parameters. param(string $key, mixed $default = null): mixed Retrieves a URL parameter.

```
$articleId = $request->param('id');
```

$key: The URL parameter key. $default: Optional. The default value to return if the key is not found. Returns: The URL parameter value. all(): array Gets all input data (GET, POST, JSON).

```
$allInputData = $request->all();
```

Returns: An array containing all input data.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance42

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

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

Total

4

Last Release

474d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8224efc6c85f9ed635239195b886766f000c05d279ba93124dcc361c235efdf7?d=identicon)[samayo](/maintainers/samayo)

---

Top Contributors

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

---

Tags

httprequestphpframeworkhttp requestfastpress

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[utopia-php/framework

A simple, light and advanced PHP HTTP framework

295618.4k9](/packages/utopia-php-framework)[utopia-php/http

A simple, light and advanced PHP HTTP framework

2962.8k2](/packages/utopia-php-http)

PHPackages © 2026

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