* @copyright Copyright (c) 2019 Brady Miller * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 */ // comment below exit command to run this test script // (when done, remember to uncomment it again) exit; require_once(__DIR__ . "/../../interface/globals.php"); use OpenEMR\Common\Csrf\CsrfUtils; use OpenEMR\Core\Header; ?> local jquery ajax call:
"; echo "
"; echo "

"; // CALL the api via a local fetch call // See above testFetchApi() function for details. echo "local fetch call:
"; echo "
"; echo "

"; // CALL the api via route handler // This allows same notation as the calls in the api (ie. '/api/facility'), but // is limited to get requests at this time. use OpenEMR\Common\Http\HttpRestRequest; use OpenEMR\Common\Http\HttpRestRouteHandler; require_once(__DIR__ . "/../../_rest_config.php"); $gbl = RestConfig::GetInstance(); $gbl::setNotRestCall(); $restRequest = new HttpRestRequest($gbl, $_SERVER); $restRequest->setRequestMethod("GET"); $restRequest->setRequestURI("/api/facility"); // below will return as json echo "api via route handler call returning json:
"; echo HttpRestRouteHandler::dispatch($gbl::$ROUTE_MAP, $restRequest, 'direct-json'); echo "

"; // below will return as php array echo "api via route handler call returning php array:
"; echo print_r(HttpRestRouteHandler::dispatch($gbl::$ROUTE_MAP, $restRequest, 'direct')); echo "

"; // CALL the underlying service that is used by the api use OpenEMR\Services\FacilityService; echo "service call:
"; echo json_encode((new FacilityService())->getAllFacility()); echo "

"; // CALL the underlying controller that is used by the api use OpenEMR\RestControllers\FacilityRestController; echo "controller call:
"; echo json_encode((new FacilityRestController())->getAll()); echo "

"; ?>