Zend Rest Client / Controller questions

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Zend Rest Client / Controller questions

Fernando
Hi,

I have some questions about Zend Rest Client and Controller. I have used SOAP for quite sometime so i'm still learning Rest and hope someone with more experience can help me:

1) Zend_Rest_Client can't consume Rest/Json services, correct? So i should simply use Zend_Http_Client for this?

2) My controller ( server ) extends Zend_Rest_Controller and i have the following action:

public function deleteAction()
{
        $this->getResponse()
                        ->setHttpResponseCode(204);
}

From what i've read, 204 code should indicate that everything went well but there is nothing to return. Meaning that the given resource was correctly deleted.

$httpClient = new Zend_Http_Client($url);
$httpClient->setHeaders('X-ApiKey', '123');
$httpClient->setParameterPost('id', $id);
$response = $httpClient->request();

This throws an exception:  Cannot handle content type '' automatically. Please use Zend_Http_Client::setRawData to send this kind of content.            

Any ideas of how to handle this correctly? How are you consuming Rest/JSON services?

Regards,

Fernando Morgenstern
[hidden email]





--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Zend Rest Client / Controller questions

lcrouch
It's been a while since I did Zend_Rest_Controller code, but from
http://framework.zend.com/manual/en/zend.http.client.html#zend.http.client.basic-requests
I would delete resources behind Zend_Rest_Controller like so:

$url = 'http://example.com/<controller>/' . $id);
$httpClient = new Zend_Http_Client($url);
$httpClient->request('DELETE');

Hope that helps.
-L

On Tue, Dec 13, 2011 at 7:59 AM, Fernando Morgenstern
<[hidden email]> wrote:

> Hi,
>
> I have some questions about Zend Rest Client and Controller. I have used SOAP for quite sometime so i'm still learning Rest and hope someone with more experience can help me:
>
> 1) Zend_Rest_Client can't consume Rest/Json services, correct? So i should simply use Zend_Http_Client for this?
>
> 2) My controller ( server ) extends Zend_Rest_Controller and i have the following action:
>
> public function deleteAction()
> {
>        $this->getResponse()
>                        ->setHttpResponseCode(204);
> }
>
> From what i've read, 204 code should indicate that everything went well but there is nothing to return. Meaning that the given resource was correctly deleted.
>
> $httpClient = new Zend_Http_Client($url);
> $httpClient->setHeaders('X-ApiKey', '123');
> $httpClient->setParameterPost('id', $id);
> $response = $httpClient->request();
>
> This throws an exception:  Cannot handle content type '' automatically. Please use Zend_Http_Client::setRawData to send this kind of content.
>
> Any ideas of how to handle this correctly? How are you consuming Rest/JSON services?
>
> Regards,
>
> Fernando Morgenstern
> [hidden email]
>
>
>
>
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]