Created
May 9, 2012 10:12
-
-
Save hewerthomn/2643533 to your computer and use it in GitHub Desktop.
.htaccess
This file contains 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
RewriteEngine on | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteRule ^(.*)$ /index.php |
This file contains 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 | |
// assume autoloader available and configured | |
$path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); | |
$path = trim($path, "/"); | |
@list($resource, $params) = explode("/", $path, 2); | |
$resource = ucfirst(strtolower($resource)); | |
$method = strtolower($_SERVER["REQUEST_METHOD"]); | |
$params = !empty($params) ? explode("/", $params) : array(); | |
if (class_exists($resource)) { | |
try { | |
$resource = new $resource($params); | |
$resource->{$method}(); | |
} | |
catch (Exception $e) { | |
header("HTTP/1.1 500 Internal Server Error"); | |
} | |
} | |
else { | |
header("HTTP/1.1 404 File Not Found"); | |
} |
This file contains 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
HTTP/1.1 405 Method Not Allowed | |
Allow: GET, POST |
This file contains 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 | |
class Restaurant extends Resource | |
{ | |
public function __construct($params) { | |
parent::__construct($params); | |
} | |
public function get() { | |
// logic to handle an HTTP GET request goes here | |
// ... | |
} | |
public function post() { | |
// logic to handle an HTTP POST request goes here | |
// ... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment