Refactor ArticleControler to ArticleController
Fix some typos
This commit is contained in:
parent
c788c9ee70
commit
471abda822
|
|
@ -5,7 +5,7 @@ namespace apisample;
|
||||||
/**
|
/**
|
||||||
* Simple class for reading and writing articles to a text file.
|
* Simple class for reading and writing articles to a text file.
|
||||||
*/
|
*/
|
||||||
class ArticlesControler {
|
class ArticlesController {
|
||||||
|
|
||||||
public $data;
|
public $data;
|
||||||
protected $path;
|
protected $path;
|
||||||
|
|
@ -1,13 +1,41 @@
|
||||||
The apisample directory contains a mini API project that demonstrates all of the
|
The apisample directory contains a mini API project that demonstrates the
|
||||||
main features of Well RESTEd.
|
main features of Well RESTEd.
|
||||||
|
|
||||||
|
Resources
|
||||||
|
---------
|
||||||
|
|
||||||
|
For this sample project, the only resources
|
||||||
|
are "articles", which are kind of like little mini blog posts or news feed
|
||||||
|
items. Each article contains the following fields:
|
||||||
|
|
||||||
|
articleId: Numeric unique identifier for the article
|
||||||
|
slug: A human readable unique identifier for the article
|
||||||
|
title: Text title describing the article
|
||||||
|
excerpt: A short portion of the article's content
|
||||||
|
|
||||||
|
In JSON, an article resource looks like this:
|
||||||
|
|
||||||
|
{
|
||||||
|
"articleId": 1,
|
||||||
|
"slug": "good-movie",
|
||||||
|
"title": "Reports Of Movie Being Good Reach Area Man",
|
||||||
|
"excerpt": "Local resident Daniel Paxson has reportedly heard dozens of accounts from numerous friendly sources in the past two weeks confirming that the new James Bond film is pretty good. According to persons with knowledge of the situation, an unnamed friend of Paxson’s coworker Wendy Mathers watched the movie on opening weekend and found it to be “decent enough.”"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
URIs
|
||||||
|
----
|
||||||
|
|
||||||
|
The API exposes both the collection of articles and each article individually.
|
||||||
|
|
||||||
/articles/
|
/articles/
|
||||||
Represents a list of articles.
|
Represents the collection of articles.
|
||||||
|
|
||||||
GET
|
GET
|
||||||
Displays a list of articles
|
Display the full list of articles.
|
||||||
POST
|
POST
|
||||||
Add a new article
|
Add a new article. Provide the new article in JSON format as the
|
||||||
|
request body.
|
||||||
PUT
|
PUT
|
||||||
Not allowed
|
Not allowed
|
||||||
DELETE
|
DELETE
|
||||||
|
|
@ -16,13 +44,14 @@ main features of Well RESTEd.
|
||||||
/articles/{id}
|
/articles/{id}
|
||||||
/articles/{slug}
|
/articles/{slug}
|
||||||
Represents one specific article identified by the numberic ID {id} or by the
|
Represents one specific article identified by the numberic ID {id} or by the
|
||||||
alpha-numeric slug.
|
alpha-numeric slug {slug}.
|
||||||
|
|
||||||
GET
|
GET
|
||||||
Displays one specific article
|
Display one specific article.
|
||||||
POST
|
POST
|
||||||
Not allowed
|
Not allowed
|
||||||
PUT
|
PUT
|
||||||
Replace the article with the given contents
|
Replace the article with the new article. Provide the new article in
|
||||||
|
JSON format as the request body.
|
||||||
DELETE
|
DELETE
|
||||||
Remove the article
|
Remove the article.
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
namespace apisample\handlers;
|
namespace apisample\handlers;
|
||||||
|
|
||||||
require_once(dirname(__FILE__) . '/../../../Handler.inc.php');
|
require_once(dirname(__FILE__) . '/../../../Handler.inc.php');
|
||||||
require_once(dirname(__FILE__) . '/../ArticlesControler.inc.php');
|
require_once(dirname(__FILE__) . '/../ArticlesController.inc.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler class for a list of articles.
|
* Handler class for a list of articles.
|
||||||
|
|
@ -16,7 +16,7 @@ class ArticleCollectionHandler extends \wellrested\Handler {
|
||||||
protected function get() {
|
protected function get() {
|
||||||
|
|
||||||
// Display the list of articles.
|
// Display the list of articles.
|
||||||
$articles = new \apisample\ArticlesControler();
|
$articles = new \apisample\ArticlesController();
|
||||||
|
|
||||||
if (isset($articles->data)) {
|
if (isset($articles->data)) {
|
||||||
|
|
||||||
|
|
@ -73,7 +73,7 @@ class ArticleCollectionHandler extends \wellrested\Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure slug is not a duplicate.
|
// Ensure slug is not a duplicate.
|
||||||
$articles = new \apisample\ArticlesControler();
|
$articles = new \apisample\ArticlesController();
|
||||||
if ($articles->getArticleBySlug($article['slug']) !== false) {
|
if ($articles->getArticleBySlug($article['slug']) !== false) {
|
||||||
$this->response->statusCode = 409;
|
$this->response->statusCode = 409;
|
||||||
$this->response->setHeader('Content-type', 'text/plain');
|
$this->response->setHeader('Content-type', 'text/plain');
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
namespace apisample\handlers;
|
namespace apisample\handlers;
|
||||||
|
|
||||||
require_once(dirname(__FILE__) . '/../../../Handler.inc.php');
|
require_once(dirname(__FILE__) . '/../../../Handler.inc.php');
|
||||||
require_once(dirname(__FILE__) . '/../ArticlesControler.inc.php');
|
require_once(dirname(__FILE__) . '/../ArticlesController.inc.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler class for one specific article.
|
* Handler class for one specific article.
|
||||||
|
|
@ -19,7 +19,7 @@ class ArticleItemHandler extends \wellrested\Handler {
|
||||||
protected function get() {
|
protected function get() {
|
||||||
|
|
||||||
// Read the list of articles.
|
// Read the list of articles.
|
||||||
$articles = new \apisample\ArticlesControler();
|
$articles = new \apisample\ArticlesController();
|
||||||
|
|
||||||
$article = false;
|
$article = false;
|
||||||
|
|
||||||
|
|
@ -89,7 +89,7 @@ class ArticleItemHandler extends \wellrested\Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the list of articles.
|
// Read the list of articles.
|
||||||
$articles = new \apisample\ArticlesControler();
|
$articles = new \apisample\ArticlesController();
|
||||||
|
|
||||||
$oldArticle = false;
|
$oldArticle = false;
|
||||||
|
|
||||||
|
|
@ -159,7 +159,7 @@ class ArticleItemHandler extends \wellrested\Handler {
|
||||||
protected function delete() {
|
protected function delete() {
|
||||||
|
|
||||||
// Read the list of articles.
|
// Read the list of articles.
|
||||||
$articles = new \apisample\ArticlesControler();
|
$articles = new \apisample\ArticlesController();
|
||||||
|
|
||||||
$article = false;
|
$article = false;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ $rqst->uri = 'https://www.google.com/search?q=my+search+terms';
|
||||||
|
|
||||||
// You could also set the members individually, like this:
|
// You could also set the members individually, like this:
|
||||||
//$rqst->protocol = 'https';
|
//$rqst->protocol = 'https';
|
||||||
//$rqst->hostname = ['www.google.com';
|
//$rqst->hostname = 'www.google.com';
|
||||||
//$rqst->path = '/search';
|
//$rqst->path = '/search';
|
||||||
//$rqst->query = array('q' => 'my search terms');
|
//$rqst->query = array('q' => 'my search terms');
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue