Are these REST HTTP response codes right, and what about the Content-Type?

Posted by talentedmrjones on Stack Overflow See other posts from Stack Overflow or by talentedmrjones
Published on 2010-05-11T18:49:03Z Indexed on 2010/05/11 18:54 UTC
Read the original article Hit count: 152

Filed under:
|
|

I'm writing a controller helper that sets the proper response headers for my REST controller action. It's pasted below and should be simplified enough for those who aren't familiar with Zend Framework to understand what I'm doing.

My question is: Are these codes correct for their respective responses, and in the case of "access denied" do I use a 401 or 403?

Also, in case of responding with an error, I understand I should be placing a message in the response body, but should I set the "Content-Type" to "text/plain"?

<?php

class App_Controller_Helper_RestResponse extends Zend_Controller_Action_Helper_Abstract
{
    public function denied()
    {
        // 403 or 401?
    }

    public function notFound()
    {
        // 404
    }

    public function created()
    {
        // 201
    }

    public function deleted()
    {
        // 204
    }


    public function redirect()
    {
        // 301
        // new url
    }

    public function malformed()
    {
        // 400
    }

    public function gone()
    {
        // 410
    }


}

© Stack Overflow or respective owner

Related posts about rest

Related posts about restful