Issues

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

Description

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


    public function delete()
    {
        $this->setMethod(Zend_Http_Client::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) {
            $this->setMethod(Zend_Http_Client::PUT);
        } else {
            $this->setMethod(Zend_Http_Client::POST);
        }
        if ($data !== null) {
            $this->setRawData($data);
        }
        return $this->request();
    }

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

Comments

Changed component from none to Zend_Http_Client

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...)

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().

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. =)

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.

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.

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.