ltonetwork / mongodb-rest

JSON REST server for MongoDB (using node.js)
MIT License
405 stars 143 forks source link

POST response could (should?) include JSON for newly created resource #24

Closed zuk closed 5 years ago

zuk commented 12 years ago

Currently a successful POST (create) results in a response that just says {"ok":1} and provides a Location header with the URL where the newly created resource can be retrieved.

This is problematic in several cases. For one, it will generally not work for POSTs done over CORS, because (for very bad reasons), the "Location" header is stripped by browsers from CORS responses. This makes retrieving info about the resource after creation impossible.

It also just doesn't work with certain REST libraries—batman.js's RestStorage is one I've had problems with—because they expect the newly created resource's data be available in the POST response body.

I'm willing to implement a solution to this. Maybe an optional config setting to enable returning the resource JSON in the POST response? But is there a good reason why I might not want to implement this?

tdegrunt commented 12 years ago

Using batman.js myself, indeed this is a problem. I'm thinking about a total rewrite (in coffeescript).

zuk commented 12 years ago

Tom, I was thinking of doing the same thing. Was gonna call it Drowsy Dromadier or Wakeful Weasel :D (see Sleepy Mongoose: http://www.snailinaturtleneck.com/blog/2010/02/22/sleepy-mongoose-a-mongodb-rest-interface/)

shangxiao commented 11 years ago

+1

AngularJS's ngResource service expects the object returned with the newly assigned ID for both POST and PUT.