-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to modify PUT to simulate PATCH #131
Comments
Wow. I am so sorry that this went unanswered for so long! At some point in the last few weeks I typed up a response to this and must have gotten sidetracked and never sent it. I'm so sorry about that! I also apologize for not making it possible to simply provide a PATCH method on collection routes. I completely understand the need for partially updating a resource. I thought I was going to implement the PATCH support a lot sooner, or I would have made more of an effort to allow a custom PATCH method to be defined on collections in the interim. As soon as I have some time to update Restivus I will be sure to add support for this. In the meantime, you can provide a custom Api = new Restivus()
# Do your partial patch (need to pass in collection since Restivus is evil and
# doesn't do it for you in collection routes
patch = (collection) ->
return ->
collection.update @urlParams.id, {$set: @bodyParams}
entity = collection.findOne @urlParams.id
# Need to check for success/failure, instead of just assuming success here
{status: 'success', data: entity}
Items = new Mongo.Collection 'Items'
Api.addCollection Items,
endpoints:
put:
action: patch(Items)
Widgets = new Mongo.Collection 'Widgets'
Api.addCollection Widgets,
endpoints:
put:
action: patch(Widgets) I just freehanded that code in a bit of a rush. If you see me doing anything glaringly stupid there just point it out and I'll fix it. Let me know if that helps. Again, I can't apologize enough for the insanely delayed response. Sorry about that! |
Thanks for getting back @kahmali and for the brilliant work so far. Although, I'm not very familiar with CoffeScript, I see that there's not $set operator implementation, is that on purpose? I shall go ahead and close this issue, though we can continue to discuss this. |
Hi guys,
Goal
We need to update documents in our collections via REST. Until JSON PATCH comes out, how can we modify PUT so that it doesn't replace the whole document, but updates the given document with new key:value pairs sent via REST. The route shouldn't update keys not mentioned in PUT.
If you know a better way to update the document which has been already implemented in restivus, please let me know.
PS: I know restivus tries to stick to standards of REST API and PUT is only supposed to replace, but we need to make do with a workaround until JSON PATCH support comes out.
The text was updated successfully, but these errors were encountered: