visionmedia / express-resource

Resourceful routing for Express
1.41k stars 140 forks source link

Allow format on create (post), update (put) and destroy(delete) requests #15

Closed 5at closed 13 years ago

5at commented 13 years ago

Is there a reason why format specifier (e.g. '.json') cannot or should not be used on create, update and/or destroy requests?

Reason I ask is that I am using the format specifier to cater to various and varied "RESTful" implementations and interpretations. i.e. support various Grids and the likes...

I have changed the line (around line number 111 of index.js):

if ('get' == method) route += '.:format?';

to:

route += '.:format?';

Initial tests show nothing has broken, and I do have a 'load' function to make sure id is extracted properly.

**Edit: Added Destroy (delete).

tj commented 13 years ago

DELETE /user/1.json ? doesn't make sense to me at least.

deedubs commented 13 years ago

HTTP allows for content to come back from a DELETE request. Could be useful for returning a status URL for delete's that are queued or take a long time. I can see how format would be useful to be able to specify this

tj commented 13 years ago

yeah you can, just seems odd to me i guess, doesn't look right. you should use Accept: application/json for that really

5at commented 13 years ago

i see your point and agree, it doesnt look right. Resource id "1.json" == Resource id "1" ?!?!?!

But by not constraining it in code you allow for both options to be available to the developer and then leave it to the developer to decide whether they use the format string or as use the Accept header.

tj commented 13 years ago

yeah totally, nothing wrong with the option. cant remember if i even have Accept support in this module yet, was working the api up to a higher level but i've been to busy

5at commented 13 years ago

How much support do you see is needed? IMHO There is already enough support in express: 1 - By reading the header 'Accept' and 2 - By using res.send or res.render to reply in the appropriate format.

Anymore than that might be complicating this framework, but that depends on what you have in mind.

tj commented 13 years ago

I'd like them to route to the individual callbacks just like we do now in express-resource for the format