shopexpress/request-response

ShopExpress Request - Response

0.8.9 2021-12-13 13:59 UTC

README

Request instantiation

$request = new \ShopExpress\RequestResponse\Request\Request('http://example.com/');

Retrieve single input from the query string

$request->query('test', 0);

Retrieve all query string data

$request->query();

Retrieve single input from request payload

$request->request('test', 0);

Retrieve all request payload data

$request->request();

Request method

$request->getMethod();

Retrieve an input item from the request

The input method retrieves values from entire request payload (including the query string). For the case of GET, HEAD request methods, request body isn't being considered.

$request->input('test', 0);

Determining if an input value is present

If you would like to determine if a value is present on the request and is not empty, you may use the filled method. For the case of GET, HEAD request methods, request body isn't being considered.

$request->filled('test');

Response

Response instantiation

$response = new \ShopExpress\RequestResponse\Response\Response(
    Request $request,
    200, 
    ['Content-Type' => 'text/html; charset=utf-8'], 
    'OK'
);

Set response body

$response->setBody('test');

Retrieve header value

$response->getHeader('Content-Type');

Add or replace header value

If you would like to add header value, pass true in the last argument

$response->withHeader('Access-Control-Allow-Methods', 'PUT', true);
$response->withHeader('Access-Control-Allow-Origin', '*');