Skip to main content
The Request class handles incoming HTTP requests and provides methods to access request data, headers, cookies, and more.

Accessing Request Data

Getting Request Payload

Retrieve data from different HTTP methods:
use Aeros\Src\Classes\Request;

$request = new Request();

// Get payload from current request method
$data = $request->getPayload();

// Get payload from specific method
$getData = $request->getPayload('GET');
$postData = $request->getPayload('POST');
$putData = $request->getPayload('PUT');

Accessing Specific Fields

Use magic methods to access request fields:
// Access field as property
$email = $request->email;
$username = $request->username;

// Check if field exists
if (isset($request->email)) {
    // Process email
}

Filtering Request Data

Only Specific Fields

Retrieve only specific fields from the request:
$request->only(['name', 'email']);
$request->only('username');

Exclude Fields

Exclude specific fields from the request:
$request->except(['password', 'token']);
$request->except('csrf_token');

Request Properties

URI and URL

// Get current URI
$uri = $request->getURI();

// Set URL for outgoing request
$request->url('https://api.example.com/endpoint');

HTTP Method

// Get current method
$method = $request->getMethod();

// Get HTTP method (works in CLI mode)
$httpMethod = $request->getHttpMethod();

// Set method for outgoing request
$request->method('POST');

Query String

// Get query string
$query = $request->getQuery();

// Set query string
$request->query('page=1&limit=10');

Headers

Getting Headers

// Get all headers
$headers = $request->getHeaders();

// Get specific header value
$contentType = $request->getHeaderValue('Content-Type');
$authToken = $request->getHeaderValue('Authorization');

Setting Headers

// Set headers for outgoing request
$request->headers([
    'Content-Type' => 'application/json',
    'Authorization' => 'Bearer token123',
    'X-Custom-Header' => 'value'
]);

Check Request Type

// Check if request is JSON
if ($request->isJson()) {
    $data = json_decode($request->getPayload(), true);
}

Cookies

Getting Cookies

// Get all cookies
$cookies = $request->getCookies();

// Access via property
$sessionId = $request->cookies['session_id'] ?? null;

Setting Cookies

// Set cookies for outgoing request
$request->cookies([
    'session_id' => 'abc123',
    'user_pref' => 'dark_mode'
]);
Cookies have a maximum size limit (default: 4096 bytes). Exceeding this limit will throw a ValueError.

Domain and Subdomain

Getting Domain Information

// Get domain
$domain = $request->getDomain();

// Get subdomain
$subdomain = $request->getSubdomain();

Setting Domain

// Set domain
$request->domain('example.com');

// Set subdomain
$request->subdomain('api');

Making Outgoing Requests

Basic Request

$request = new Request();

$response = $request
    ->url('https://api.example.com/users')
    ->method('GET')
    ->send();

POST Request with Payload

$response = $request
    ->url('https://api.example.com/users')
    ->method('POST')
    ->setPayload([
        'name' => 'John Doe',
        'email' => '[email protected]'
    ])
    ->send();

Request with Custom Headers

$response = $request
    ->url('https://api.example.com/data')
    ->headers([
        'Authorization' => 'Bearer token123',
        'Accept' => 'application/json'
    ])
    ->send();

SSL Configuration

Disabling SSL verification is a security risk and should only be used in development environments.
// Enable SSL verification (default)
$request->ssl(true);

// Disable SSL verification (development only)
$request->ssl(false);
SSL verification cannot be disabled in production environments. Attempting to do so will throw an exception.

Advanced Usage

Merging Payload

// Replace entire payload
$request->setPayload(['name' => 'John'], false);

// Merge with existing payload
$request->setPayload(['email' => '[email protected]'], true);

Magic Methods

// Set field
$request->username = 'johndoe';

// Get field
$username = $request->username;

// Check if set
if (isset($request->username)) {
    // Field exists
}

// Unset field
unset($request->password);

Security Features

Automatic Input Sanitization

All input data is automatically sanitized to remove:
  • Null bytes
  • Excess whitespace

URL Length Limits

// URLs exceeding max length throw ValueError
// Default: 2048 characters (configurable)
$request->url($longUrl);

Header Count Limits

// Maximum header count is enforced
// Default: 50 headers (configurable)
$request->headers($manyHeaders);

Build docs developers (and LLMs) love