Skip to content

Instantly share code, notes, and snippets.

@aaronlifton3
Last active December 11, 2015 12:38
Show Gist options
  • Save aaronlifton3/4601562 to your computer and use it in GitHub Desktop.
Save aaronlifton3/4601562 to your computer and use it in GitHub Desktop.
rest ftw bro, zf
<?php
public function indexAction()
{
$this->getResponse()->setBody('List of Resources');
$this->getResponse()->setHttpResponseCode(200);
}
public function getAction()
{
$this->getResponse()->setBody(sprintf('Resource #%s', $this->_getParam('id')));
$this->getResponse()->setHttpResponseCode(200);
}
public function postAction()
{
$this->getResponse()->setBody('Resource Created');
$this->getResponse()->setHttpResponseCode(201);
}
public function putAction()
{
$this->getResponse()->setBody(sprintf('Resource #%s Updated', $this->_getParam('id')));
$this->getResponse()->setHttpResponseCode(201);
}
public function deleteAction()
{
$this->getResponse()->setBody(sprintf('Resource #%s Deleted', $this->_getParam('id')));
$this->getResponse()->setHttpResponseCode(200);
}
?>
// clean RESTFUL response:
curl -v http://localhost/v1/foo
curl -v -X GET http://localhost/v1/foo/1
curl -v -X POST http://localhost/v1/foo
curl -v -X PUT -d '' http://localhost/v1/foo/1
curl -v -X DELETE http://localhost/v1/foo/1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment