hostas2/public/api/v1/router.php

19 lines
582 B
PHP

<?php
require_once($_SERVER['DOCUMENT_ROOT'] . '/config.php');
// $clean_uri is the request URI with any query strings removed
$clean_uri = strtok($_SERVER['REQUEST_URI'], '?');
// e.g. /api/v1/test/request/ -> ['', 'api', 'v1', 'test', 'request'].
// For convenience later, we take a slice that excludes ['', 'api', 'v1'].
define('REQUEST_PATH', array_slice(explode('/', $clean_uri), offset: 3));
switch (REQUEST_PATH[0]) {
case 'actor': // /api/v1/actor
require_once($_SERVER['DOCUMENT_ROOT'] . '/api/v1/actor.php');
break;
default:
http_response_code(404);
die();
}