Skip to content

pouriamdr/easyRestAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

easyRestAPI

Code less with this useful Rest API class.

Installation

It is simple, import easyRestAPI.php in your project using include like this:
<?
include_once("/path/to/easyRestAPI.php");

Introduce

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.

About

Code less with this useful Rest API class.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages