2

I have referred many articles in the web on this subject but got only basic examples. I got some practical issues.

1). In Zend_Rest_Controller there are abstract methods for get, post, put and delete. how do I create my own function rather thean using getAction, postAction, etc... in order to respond for a get request (Ex: api.abc.com/product/5 - That will return set of products from a category 5)?

2). Is it possible to enable rest routing only for a specific controller in a module?

Can you give some example or some article?

Shaolin
  • 2,541
  • 4
  • 30
  • 41

1 Answers1

0

I will try to answer this, since I've created an API using Zend_Rest_Controller, but since the project is not public, i can only copy-paste so much.

1) Well you should use these methods. They are helpful in that they kind of force you to think in terms of every controller being a resource. So for each resource you should only be able to define the GET verb once.

public function getAction()
{
    if (!is_null($this->getParam("id"))) {
        $this->view->user = $userModel->getUserById($this->getParam("id",null));
        $this->_helper->viewRenderer('get-user');
    } else {
        $userModel = new Model_Users();
        $this->view->users = $userModel->getUsers();
        $this->_helper->viewRenderer('get-all-users');
    }
}

2) Well out of the box - I think no. But that should not be a bad thing, since you should put all of the rest functionality in a seperate module anyways.

Janis Peisenieks
  • 4,938
  • 10
  • 55
  • 85