ZF-5875: Add convenience methods: head, delete, post, put

Issue Type: Improvement Created: 2009-02-24T07:20:04.000+0000 Last Updated: 2012-01-13T15:45:52.000+0000 Status: Open Fix version(s): Reporter: Till Klampaeckel (till) Assignee: Shahar Evron (shahar) Tags: - Zend_Http_Client

Related issues: Attachments:


As an example, this is how I could implement delete(), put() and post():

<pre class="highlight">
    public function delete()
        return $this->request();

    public function post($data = null)
        return $this->makePostPutRequest(Zend_Http_Client::POST, $data);

    public function put($data = null)
        return $this->makePostPutRequest(Zend_Http_Client::PUT, $data);

    protected function makePostPutRequest($method, $data = null)
        if ($method == Zend_Http_Client::PUT) {
        } else {
        if ($data !== null) {
        return $this->request();

If you give me some feedback, I could do other things as well and commit these things if you want to.


Posted by Dolf Schimmel (Freeaqingme) (freak) on 2009-02-24T07:24:18.000+0000

Changed component from none to Zend_Http_Client

Posted by Trevor Johns (tjohns) on 2009-02-26T10:44:04.000+0000

Hi Till, For post(), you might want to include the encoding type as a parameter, because that's rather important.

Also, if you're going to do this, why not include the other request types?

Finally, request() allows you to specify a method as an argument. By using that, you avoid duplicating code.

(Conversely, request('post') isn't that much more difficult than post(), so I'm not sure whether this improvement justifies the additional bloat...)

Posted by Matthew Ratzloff (mratzloff) on 2009-02-26T12:56:32.000+0000

You could implement these methods as concrete methods that support IDE autocompletion, or you could forego that, reduce bloat, and increase flexibility (in edge cases, like a native PHP WebDAV implementation) by implementing it with __call().

Posted by Till Klampaeckel (till) on 2009-11-01T08:39:13.000+0000

I don't understand why this took so long and is looked on as bloat. It doesn't make code slower if you don't use it.

In summary, this is yet another issue that took way to long to go anywhere. I've since moved on and use my own client, implementing put(), post(), get(), delete() and head().

Thanks, mucho. =)

Posted by Marc Hodgins (mjh_ca) on 2010-11-10T10:41:33.000+0000

ZF2.0 is going toward removing the magic and favoring explicit behavior for a number of good reasons.

+1 that if this is implemented then they should be concrete methods and not magic methods.

Posted by Bart McLeod ( on 2011-07-17T20:15:52.000+0000

This has indeed taken very, very long. I am currently investigating Zend_Http_Client in the 1.11 version looking to improve the sending of PUT and DELETE data, which is currently impossible. There is an issue filed about that. Adding convenience methods (real methods) would be nice.

On the other hand, there are more urgent problems, such as regression, errors failing unit tests... I am tempted to assign this to me, but my main goal at present is to fix Zend_Rest_Client, that can't send data along with a PUT or DELETE request. So I 'll just watch this. By the way, improvements should now be targeted at version 2.0.

Posted by Till Klampaeckel (till) on 2012-01-13T15:45:52.000+0000

I think Zend_Http_Client has been dead for a long time. I'm not sure how the client library will look like in ZF2, but I wouldn't wait for it.

Unless you have code already, I suggest you link into Guzzle or Buzz.

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.