RestServer icon indicating copy to clipboard operation
RestServer copied to clipboard

PUT requests not working?

Open TheRealGuru opened this issue 8 years ago • 2 comments

Hi, maybe the documentation is unclear not sure. However my put request is just not working.


    /**
     * Marks a game as completed
     *
     *
     * @url PUT /game/end
     */
    public function endGame($data) {
        print_r($data);
    }

This just won't work, the data variable contains absolutely nothing. I've tried to via a PHP curl request and a linux curl request.

PHP Request

        $data = array('test' => 'test');
        $ch = curl_init('theurl');

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
        curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($data));

        $response = curl_exec($ch);
        echo $response;

Linux cURL

 curl -i -H "Accept: application/json" -X PUT -d test=test url

TheRealGuru avatar Jun 21 '16 20:06 TheRealGuru

It appears to be a bug. While the server supports multiple formats for returning data (JSON, XML, text, etc), it only accepts JSON data for POSTs and PUTs. I suppose most people just use this server for JSON and so we haven't discovered this error until now.

If you're going with JSON anyway you could just pass JSON data in and it would work. If you want to support application/x-www-form-urlencoded data you'll need to update the getData() method to parse the content type being sent and work accordingly. Pull requests welcome!

jacwright avatar Jun 22 '16 19:06 jacwright

The question is if it works by specifying JSON. If it does, I'd be happy to tag this as a feature-request.

tyzoid avatar Jul 18 '17 02:07 tyzoid