Luracast / Restler

Simple and effective multi-format Web API Server to host your PHP API as Pragmatic REST and/or RESTful API
http://luracast.com/products/restler/
GNU Lesser General Public License v2.1
1.36k stars 315 forks source link

PUT vs POST post-data #623

Closed dosfx closed 3 years ago

dosfx commented 5 years ago

I have a function on the server with a few parameters. If I set it as a POST request it will work, but if I set it as a PUT it will fail at validation, saying that it requires the first param. I can switch back and forth changing nothing else, and it will work as a POST, but fail as a PUT.

I'm using both Postman and axios js. Sending as Content-Type: multipart/form-data, both exhibit the same behaviour, works with POST, but not with PUT.

/**
 * @url PUT
 * @param string $ObjId
 */
function updateObject($ObjId) {}
var formData = new FormData();
formData.append("ObjId", "THIS-IS-A-GUID");
axios.put("localhost:3000/object", formData);

What am I doing wrong?

davidsneighbour commented 5 years ago

The POST creates a new object, the PUT changes an existing one. So the first parameter of PUT is the objectid of the object you want to update.

I don't fully understand your code, but maybe:

axios.put("localhost:3000/object/"+ObjId, formData);

does the trick.

Arul- commented 3 years ago

Thanks, @davidsneighbour for the explanation on PUT

@dosfx along with the id it needs the data to be saved as well!