Code less with this useful Rest API class.
It is simple, import easyRestAPI.php in your project using include like this:<?
include_once("/path/to/easyRestAPI.php");
First create object of easyRestAPI class where you want handle requests and change settings if you want:
<?
include_once("/path/to/easyRestAPI.php");
$rest = new easyR();
// SETTINGS
$rest->useFilters = TRUE;
$rest->saveLogs = TRUE;
$rest->defaultLogFile = 'my-logs.log';
date_default_timezone_set('Asia/Tehran'); // For saving logs with your custom timezone.
// END OF SETTINGS
Then parse inputs:
$inputs = $rest->inputs; // Get all income data
if($inputs['username']['method'] != 'POST') {
die('Invalid request!');
}
print_r($inputs);
/*
# Result
array(
'username' => array(
'value' => 'pouria',
'method' => 'POST'
),
'password' => array(
'value' => 'XXXXXXXXX',
'method' => 'POST'
)
)
*/
At the end send your response:
$responseAs = 'json'; // Or text
$rest->response('OK', $responseAs);
/*
Prepared responses are listed bellow:
OK
SUCCESS
ERROR
INTERNAL-ERROR
AUTH-ERROR
ACCESS-DENIED
FAILOR
AUTH-FAILOR
BAD-REQUEST
----------
For see all details about responses use "print_r($rest->responses);"
*/
Hope this simple library helps in your projects, Good luck.