Created
October 11, 2019 13:55
-
-
Save BlakeStevenson/aae2f11c3adc2a211c4a6213459415d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// set JSON header | |
header('Content-Type: application/json'); | |
// check for version | |
if($_SERVER['REQUEST_URI'] === "/v1") { | |
// select endpoint | |
switch($_SERVER['REQUEST_URI']) { | |
case "v1/user": | |
require_once "endpoints/user.php"; | |
break; | |
case "v1/post": | |
require_once "endpoints/post.php"; | |
break; | |
default: | |
require_once "endpoints/default.php"; | |
} | |
} else { | |
// display error if version not passed. | |
header('HTTP/1.1 400 Bad Request'); | |
$response = array( | |
"status" => "HTTP/1.1 400 Bad Request", | |
"message" => "Invalid API Version", | |
"acceptable" => array("v1") | |
); | |
echo json_encode($response, JSON_PRETTY_PRINT); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment