Flight encapsulates the HTTP request into a single object, which can be accessed by doing:
$request = Flight::request();
The request object provides the following properties:
You can access the query, data, cookies, and files properties as arrays or objects.
query
data
cookies
files
So, to get a query string parameter, you can do:
$id = Flight::request()->query['id'];
Or you can do:
$id = Flight::request()->query->id;
To get the raw HTTP request body, for example when dealing with PUT requests, you can do:
$body = Flight::request()->getBody();
If you send a request with the type application/json and the data {"id": 123} it will be available from the data property:
application/json
{"id": 123}
$id = Flight::request()->data->id;
There is a shortcut available to access the $_SERVER array via the getVar() method:
$_SERVER
getVar()
$host = Flight::request()->getVar['HTTP_HOST'];
You can access request headers using the getHeader() or getHeaders() method:
getHeader()
getHeaders()
// Maybe you need Authorization header $host = Flight::request()->getHeader('Authorization'); // If you need to grab all headers $headers = Flight::request()->getHeaders();