SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
807 stars 171 forks source link

Unsupported method ('PUT') #47

Closed marcmmx closed 9 years ago

marcmmx commented 9 years ago

I try to update a document via Angularjs controller as following

$http.put("/db/persons/"+person._id, person).success(function(result) { ...

and get following error message 127.0.0.1 - - [29/Aug/2015 20:39:44] code 501, message Unsupported method ('PUT')

The security.yml part looks as following: permissions:

Are there any ideas what could be wrong here or is put not supported yet? Thanks.

ujibang commented 9 years ago

PUT verb on document URI is supported. It upserts the document with the provided data (in case of updates you need to pass the ETag with the If-Match request header).

Please provide more info: what is the value of person._id? Any log message from restheart? Can you check the actual request with the browser inspector?...

Can you also try the PUT with curl or httpie?

What is the value of the mongo-mount parameter in configuration file?

marcmmx commented 9 years ago

Thanks for the feedback. I will investigate your suggestions and let you know. I close the issue now.

marcmmx commented 9 years ago

Please can you provide a small AngularJS PUT example where I can update a person object?

ujibang commented 9 years ago

please have a look at the restheart-blog-example, done with AngularJs

this is the file you are interested on:

https://github.com/SoftInstigate/restheart-blog-example/blob/master/app/components/edit/edit.js

it actually uses $http.post, but you can easily modify to use $http.put

Note that if you post a collection with a document not containing the id, a document gets created with a new id (ObjectId). If the data includes an id, and it exists, it will be upated.

Note also that if the id is an ObjectId, you build the URI of the document this way:

$http.put('/db/coll/' + doc._id.$oid, data)....

marcmmx commented 9 years ago

Thanks again. It worked now.