Imitate the REST api using url parameter based implementation
Reason for this implementation is some clients having trouble configuring the rest api either due to not having proper access to the webserver in a shared hosting environment or security restrictions. But still from icehrm frontend we need to consume the backend rest api.
This commit is contained in:
41
core/api.php
Normal file
41
core/api.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
define('CLIENT_PATH',dirname(__FILE__));
|
||||
include ("config.base.php");
|
||||
include ("include.common.php");
|
||||
include("server.includes.inc.php");
|
||||
|
||||
if(\Classes\SettingsManager::getInstance()->getSetting('Api: REST Api Enabled') == '1') {
|
||||
|
||||
\Utils\LogManager::getInstance()->info("Request: " . $_REQUEST);
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
||||
http_response_code(200);
|
||||
exit();
|
||||
}
|
||||
|
||||
define('REST_API_PATH', '/');
|
||||
|
||||
$echoRoute = \Classes\Macaw::get(REST_API_PATH . 'echo', function () {
|
||||
echo "Echo " . rand();
|
||||
});
|
||||
|
||||
\Utils\LogManager::getInstance()->debug('Api registered URI: '.$echoRoute);
|
||||
|
||||
$moduleManagers = \Classes\BaseService::getInstance()->getModuleManagers();
|
||||
|
||||
foreach ($moduleManagers as $moduleManagerObj) {
|
||||
|
||||
$moduleManagerObj->setupRestEndPoints();
|
||||
}
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
if (strtoupper($method) === 'GET') {
|
||||
\Classes\IceRoute::dispatch($_GET['url'], $method);
|
||||
} else {
|
||||
$method = strtoupper($_REQUEST['method']);
|
||||
\Classes\IceRoute::dispatch($_REQUEST['url'], $method);
|
||||
}
|
||||
|
||||
|
||||
}else{
|
||||
echo "REST Api is not enabled. Please set 'Api: REST Api Enabled' setting to true";
|
||||
}
|
||||
Reference in New Issue
Block a user