views:

252

answers:

2

I'm trying to create a REST service in zend framework. I'm using zend server.

Here's my code:

class ArticleController extends Zend_Rest_Controller
{
  public function postAction()
  {
    //Create the acticle and return it
    $data = array("foo" => 0, "boo" => 11);
    $this->getResponse()->setHttpResponseCode(201);
    $this->_helper->json($data);
  }

The HTTP response returns the appropriate headers and JSON data but under the JSON data there's an apache error document. The only way I can think of to remove the appended error document is to add the following in my httpd.conf file:

ErrorDocument 201 " "

But what's the "corrent" way of doing this?

A: 

Why are you using code 201? 201 means you have created a resource for the request and are providing a link to it. If you have the article and are returning it you should just use 200.

Otherwise, what you're doing seems like the correct way, you remove the ErrorDocument associated with status-code 201.

Arda Xi
+2  A: 

Your original way is correct. 201 is an appropriate response after POSTing a new resource.

I think that the Error document which you see generated after your own content should not be there. Are you running Zend Server Community Edition v5.0 by any chance? If yes, then see this thread, I think that you encountered the same problem as the other guy there:
http://stackoverflow.com/questions/2461315/how-to-turn-off-default-http-status-code-errors-in-zend-server

MicE