Skip to main content
The Request class handles both incoming HTTP requests and outgoing cURL requests. It provides a fluent interface for working with request data, headers, cookies, and validation.

Accessing the request

Access the current request instance:
$request = app()->request;

HTTP method information

getMethod()

Get the HTTP method of the current request.
$method = app()->request->getMethod(); // 'GET', 'POST', etc.
return
string
Returns the HTTP method (GET, POST, PUT, PATCH, DELETE)

getHttpMethod()

Retrieve the HTTP method from the server.
$method = app()->request->getHttpMethod();
return
string
Returns the HTTP method from $_SERVER[‘REQUEST_METHOD’]

URI and URL methods

getURI()

Get the current request URI.
$uri = app()->request->getURI(); // '/users/123'
return
string
Returns the current URI without query string

url()

Set the target URL for outgoing requests.
app()->request->url('https://api.example.com/users');
url
string
required
The target URL
return
Request
Returns Request instance for method chaining

getQuery()

Get the query string from the request.
$query = app()->request->getQuery(); // 'page=1&limit=10'
return
string
Returns the query string

Domain and subdomain

getDomain()

Get the current domain.
$domain = app()->request->getDomain(); // 'example.com'
return
string|null
Returns the current domain or null

getSubdomain()

Get the current subdomain.
$subdomain = app()->request->getSubdomain(); // 'api'
return
string|null
Returns the current subdomain or null

Request payload

getPayload()

Retrieve the payload data based on HTTP method.
// Get POST data
$data = app()->request->getPayload();

// Get data from specific method
$getData = app()->request->getPayload('GET');
$postData = app()->request->getPayload('POST');
$files = app()->request->getPayload('FILES');
from
string
default:"null"
HTTP method to retrieve payload from (defaults to current method)
return
array
Returns associative array of payload data

setPayload()

Set the payload data for outgoing requests.
app()->request
    ->setPayload(['name' => 'John', 'email' => '[email protected]'])
    ->send();

// Merge with existing payload
app()->request->setPayload(['age' => 30], merge: true);
data
mixed
required
Data to set as payload
merge
bool
default:"false"
If true, merges with existing payload
return
Request
Returns Request instance for method chaining

Headers

getHeaders()

Get all request headers.
$headers = app()->request->getHeaders();
return
array
Returns array of headers

headers()

Set request headers.
app()->request->headers([
    'Authorization' => 'Bearer token123',
    'Content-Type' => 'application/json'
]);
headers
array
required
Associative array of headers
return
Request
Returns Request instance for method chaining

getHeaderValue()

Get a specific header value by name.
$authHeader = app()->request->getHeaderValue('Authorization');
name
string
required
Header name (case-insensitive)
return
string|null
Returns header value or null if not found

Cookies

getCookies()

Retrieve all cookies.
$cookies = app()->request->getCookies();
return
array
Returns array of cookies

cookies()

Set cookies for the request.
app()->request->cookies([
    'session_id' => 'abc123',
    'user_pref' => 'dark_mode'
]);
cookies
array
default:"[]"
Associative array of cookies
return
Request
Returns Request instance for method chaining

Validation

validate()

Validate and filter payload against defined rules.
$validated = app()->request->validate([
    'email' => FILTER_VALIDATE_EMAIL,
    'age' => FILTER_VALIDATE_INT,
    'name' => FILTER_SANITIZE_STRING
]);
filters
array
required
Filter rules (same format as filter_var_array)
throwOnError
bool
default:"true"
If true, throws exception on validation failure
return
array
Returns filtered and validated payload

validateWith()

Quick validation with predefined rules.
$validated = app()->request->validateWith([
    'email' => 'email',
    'age' => 'int',
    'website' => 'url',
    'active' => 'boolean'
]);
rules
array
required
Array of field => rule mappings
return
array
Returns validated data

validateField()

Validate a single field from the payload.
$email = app()->request->validateField('email', FILTER_VALIDATE_EMAIL);
field
string
required
Field name to validate
filter
int|array
required
Filter constant or array with filter options
return
mixed
Returns filtered value or null if validation fails

validationRules()

Get available validation rule patterns.
$rules = Request::validationRules();
// Returns: ['email' => FILTER_VALIDATE_EMAIL, 'url' => FILTER_VALIDATE_URL, ...]
return
array
Returns array of predefined validation rules

Filtering data

only()

Get only specific keys from the request.
$data = app()->request->only(['name', 'email']);
keys
string|array
required
Field name(s) to include
return
Request
Returns Request instance for method chaining

except()

Get all keys except specified ones.
$data = app()->request->except(['password', 'password_confirmation']);
keys
string|array
required
Field name(s) to exclude
return
Request
Returns Request instance for method chaining

Making outgoing requests

method()

Set the HTTP method for outgoing requests.
app()->request->method('POST');
method
string
default:""
HTTP method (GET, POST, PUT, PATCH, DELETE)
return
Request
Returns Request instance for method chaining

ssl()

Enable or disable SSL verification.
app()->request->ssl(false); // Disable SSL verification (development only)
ssl
bool
required
Enable/disable SSL verification
return
Request
Returns Request instance for method chaining

send()

Send the cURL request.
$response = app()->request
    ->url('https://api.example.com/users')
    ->method('POST')
    ->setPayload(['name' => 'John'])
    ->headers(['Authorization' => 'Bearer token'])
    ->send();
return
string|bool
Returns response data or error message

Utility methods

isJson()

Check if the request content type is JSON.
if (app()->request->isJson()) {
    $data = json_decode($input, true);
}
return
bool
Returns true if Content-Type is application/json

Examples

Handle form submission

class UserController extends Controller
{
    public function store()
    {
        $validated = app()->request->validateWith([
            'name' => 'string',
            'email' => 'email',
            'age' => 'int'
        ]);

        $user = User::create($validated);
        return response()->type($user, 201, Response::JSON);
    }
}

Make API request

$response = app()->request
    ->url('https://api.github.com/users/octocat')
    ->method('GET')
    ->headers([
        'Accept' => 'application/json',
        'User-Agent' => 'Aeros-Framework'
    ])
    ->send();

Filter request data

// Get only specific fields
$credentials = app()->request->only(['email', 'password']);

// Exclude sensitive fields from logging
$logData = app()->request->except(['password', 'token']);

Custom validation

$data = app()->request->validate([
    'email' => FILTER_VALIDATE_EMAIL,
    'age' => [
        'filter' => FILTER_VALIDATE_INT,
        'options' => ['min_range' => 18, 'max_range' => 120]
    ],
    'website' => FILTER_VALIDATE_URL
]);

Build docs developers (and LLMs) love