diff --git a/samples/apisample/.htaccess b/samples/apisample/.htaccess new file mode 100644 index 0000000..2e96de0 --- /dev/null +++ b/samples/apisample/.htaccess @@ -0,0 +1,8 @@ +RewriteEngine on +RewriteBase /wellrested/samples/apisample/ + +# Send all requests to non-regular files and directories to router.php +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^.+$ index.php [L,QSA] + diff --git a/samples/apisample/ApiSampleRouter.inc.php b/samples/apisample/ApiSampleRouter.inc.php new file mode 100644 index 0000000..92660af --- /dev/null +++ b/samples/apisample/ApiSampleRouter.inc.php @@ -0,0 +1,40 @@ +addTemplate('/articles/', + '\handlers\ArticleCollectionHandler', + 'ArticleCollectionHandler.inc.php'); + + $this->addTemplate('/articles/{id}', + '\handlers\ArticleItemHandler', + 'ArticleItemHandler.inc.php', + array('id' => \wellrested\Route::RE_NUM)); + + $this->addTemplate('/articles/{slug}', + '\handlers\ArticleItemHandler', + 'ArticleItemHandler.inc.php', + array('slug' => \wellrested\Route::RE_SLUG)); + + } + + public function addTemplate($template, $handlerClassName, $handlerFilePath, $variables=null) { + + // Customize as needed based on your server. + $template = '/wellrested/samples/apisample' . $template; + $handlerFilePath = dirname(__FILE__) . '/handlers/' . $handlerFilePath; + + $this->addRoute(\wellrested\Route::newFromUriTemplate( + $template, $handlerClassName, $handlerFilePath, $variables)); + + } + +} + +?> \ No newline at end of file diff --git a/samples/apisample/handlers/ArticleCollectionHandler.inc.php b/samples/apisample/handlers/ArticleCollectionHandler.inc.php new file mode 100644 index 0000000..385e4ec --- /dev/null +++ b/samples/apisample/handlers/ArticleCollectionHandler.inc.php @@ -0,0 +1,19 @@ +response->statusCode = 200; + $this->response->setHeader('Content-type', 'text/plain'); + $this->response->body = 'A list of articles.'; + + } + +} + +?> diff --git a/samples/apisample/handlers/ArticleItemHandler.inc.php b/samples/apisample/handlers/ArticleItemHandler.inc.php new file mode 100644 index 0000000..59b0d95 --- /dev/null +++ b/samples/apisample/handlers/ArticleItemHandler.inc.php @@ -0,0 +1,20 @@ +response->statusCode = 200; + $this->response->setHeader('Content-type', 'text/plain'); + $this->response->body = 'One article'; + $this->response->body = print_r($this->args, true); + + } + +} + +?> diff --git a/samples/apisample/index.php b/samples/apisample/index.php new file mode 100644 index 0000000..fcc432f --- /dev/null +++ b/samples/apisample/index.php @@ -0,0 +1,10 @@ +getResponse(); +$response->respond(); +exit; + +?> \ No newline at end of file