Skip to main content

Overview

The Request class provides a clean interface for accessing HTTP request data including query parameters, POST data, JSON payloads, headers, and server variables.
The Request class automatically parses JSON request bodies when the Content-Type is application/json.

Constructor

Create a new Request instance from global PHP variables.

Example

Static Methods

capture

Create a Request instance from the current HTTP request.

Returns

Request
New Request instance populated with current request data

Example

Input Methods

get

Retrieve a query string parameter from the URL.
string
required
Query parameter name
mixed
default:"null"
Default value if parameter doesn’t exist

Returns

mixed
Query parameter value or default

Example

post

Retrieve a POST form parameter.
string
required
POST parameter name
mixed
default:"null"
Default value if parameter doesn’t exist

Returns

mixed
POST parameter value or default

Example

input

Retrieve input from JSON body, POST, or GET (in that order of priority).
string
required
Input parameter name
mixed
default:"null"
Default value if parameter doesn’t exist

Returns

mixed
Input parameter value or default
The input() method is the recommended way to retrieve data as it checks JSON body first, then POST, then GET parameters.

Example

all

Get all input data merged from GET, POST, and JSON body.

Returns

array
All request input as an associative array

Example

getJson

Get the parsed JSON body if available.

Returns

array|null
Parsed JSON data or null if request body is not JSON

Example

Request Information

method

Get the HTTP request method.

Returns

string
HTTP method (GET, POST, PUT, DELETE, etc.)

Example

uri

Get the request URI path without query string.

Returns

string
Request URI path

Example

ip

Get the client’s IP address.

Returns

string
Client IP address

Example

Headers

Get a specific HTTP header value.
string
required
Header name (case-insensitive, automatically converted)
mixed
default:"null"
Default value if header doesn’t exist

Returns

mixed
Header value or default
Header names are automatically converted to the HTTP_* format. For example, Content-Type becomes HTTP_CONTENT_TYPE.

Example

Common Patterns

Validating Input

Handling JSON Requests

Pagination with Query Parameters

API Authentication

File Upload Information

Request Logging

Complete Example