PHP code example of zeptech / php-rest-server
1. Go to this page and download the library: Download zeptech/php-rest-server library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zeptech / php-rest-server example snippets
try {
$srvr = new \zeptech\rest\RestServer();
// RequestHandlerImpl must implement \zeptech\rest\RequestHandler
// \zeptech\rest\BaseRequestHandler can be extended if you only need to handle
// a subset of the available actions.
$srvr->addMapping('/', new RequestHandlerImpl());
if (!empty($_GET)) {
$server->setQuery($_GET);
}
if (!empty($_POST)) {
$server->setData($_POST);
}
$server->setAcceptType($_SERVER['HTTP_ACCEPT']);
$server->handleRequest($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);
$response = $server->getResponse();
$headers = $server->getResponseHeaders();
foreach ($headers as $hdr) {
header($hdr);
}
echo $response;
} catch (Exception $e) {
error_log($e->getMessage());
error_log($e->getTraceAsString());
header('HTTP/1.1 500 Internal Server Error');
echo $e->getMessage();
}