Request

The Request class provides a unified, object-oriented interface for interacting with the current HTTP request. It simplifies access to $_GET, $_POST, $_FILES, $_COOKIE, and $_SERVER superglobals, and provides helpers for handling JSON input, headers, and validation.

Capabilities

  • Access GET, POST, and JSON data.

  • Check for the existence of parameters.

  • Validate input data against a set of rules.

  • Sanitize input to prevent XSS attacks.

  • Access headers, cookies, server variables, and uploaded files.

  • Helpers for request method, URI, and AJAX detection.

Public API

Data Retrieval

// Get all input data (GET, POST, JSON)
all(): array

// Get a value from any source (GET > POST > JSON)
query(string $key, $default = null)

// Get a value from query string ($_GET)
get(string $key, $default = null)

// Get a value from a POST form ($_POST)
post(string $key, $default = null)

// Get the full JSON body or a specific key
json(?string $key = null, $default = null)

Existence Checks

Validation

CSRF Protection

Sanitization

Request Metadata

Basic Example

Last updated