Skip to content

Requests

Request object can be accessed in callback functions of:

Request properties

PropertyTypeDescription
methodstringRequest method
methodEnumRequestMethod|nullMethod as enum
pathstring|nullRequested path
routeParamsarrayRoute parameters of dynamic paths
queryParamsarrayQuery parameters
headersarrayRequest headers
contentTypestring|nullContent-Type header
acceptstring|nullAccept header
cookiesarrayShorthand for $_COOKIE
ipstring|nullShorthand for $_SERVER['REMOTE_ADDR']
userAgentstring|nullShorthand for $_SERVER['HTTP_USER_AGENT']
protocolstring|nullShorthand for $_SERVER['SERVER_PROTOCOL']
bodymixedRequest body
filesarrayNormalized value of $_FILES

Body

If the request Content-Type header is application/json, the request body will be parsed from php://input. In such cases, the body must be a valid JSON string. If the JSON is malformed, an ApiException will be thrown.

For all other cases, the body will contain the raw value of $_POST superglobal.

Files

By default, $_FILES superglobal has a non-intuitive structure when it contains multiple files for the same field. files property contains a normalized value. The structure is always an array, regardless of the number of files.

Single file

json
{
  "my_file_field": [
    {
      "name": "foo.txt",
      "full_path": "foo.txt",
      "type": "text/plain",
      "tmp_name": "/tmp/phprawUMP",
      "error": 0,
      "size": 4
    }
  ]
}

Multiple files

json
{
  "my_file_field": [
    {
      "name": "foo.txt",
      "full_path": "foo.txt",
      "type": "text/plain",
      "tmp_name": "/tmp/phprawUMP",
      "error": 0,
      "size": 4
    },
    {
      "name": "bar.txt",
      "full_path": "bar.txt",
      "type": "text/plain",
      "tmp_name": "/tmp/php8P7qcq",
      "error": 0,
      "size": 4
    }
  ]
}

Request methods

routeParam()

Get route parameter. If parameter is not found, null is returned.

php
$request->routeParam('product');

queryParam()

Get query parameter. If parameter is not found, null is returned.

php
$request->queryParam('product');

toArray()

Return all request properties as an associative array.

php
$request->toArray();

Released under the MIT License.