Zend Framework 1にRESTfulデザインを実装したいのですが、リソースを文書化する方法、許可されているメソッド、および提供できる追加のパラメーターがわかりません。
私の現在の実装では、リソースとしてコントローラー名を使用しており、HTTPメソッドはアクション名です。私はすでに以下を含むヘッダーで「許可」を送信しています:
GET, PUT, PATCH, LINK, UNLINK, POST, DELETE, HEAD, OPTIONS
クライアントの可能なパラメータと必要なパラメータをどのように文書化できるのか疑問に思っています。
- 一般的なDocBlockの規則はありますか?
- HTTPヘッダー(「許可」部分など)を使用して、可能な追加パラメーターを「自動文書化」することは可能ですか?
現在、DocBlock属性を作成し、「OPTIONS」リクエストで送信しています。
/**
* @route /data/results
* @method GET
* @requiredParams pid The project ID
* @queryParams tid The team ID
*/
public function getAction()
{
$pid = $this->_getParam('pid');
$teamId = $this->_getParam('tid');
if (null === $pid) {
$this->getResponse()->setHttpResponseCode(400);
$this->getResponse()
->setBody(Zend_Json::encode(array('required parameters missing')));
} else {
$this->getResponse()->setBody(Zend_Json::encode(array($pid, $teamId)));
$this->getResponse()->setHeader('Content-Type', 'application/json');
$this->getResponse()->setHttpResponseCode(200);
}
}
public function optionsAction()
{
$reflect = new Zend_Reflection_Class($this);
foreach (explode(',',$this->getAllowedMethods()) as $method) {
$action = strtolower(trim($method)) . 'Action';
try {
$docs[] = $method.' '.$reflect->getMethod($action)
->getDocblock()->getContents();
} catch(Zend_Reflection_Exception $e) {
}
}
$this->getResponse()->setBody(implode("\n",$docs));
$this->getResponse()->setHttpResponseCode(200);
}