Reputation: 151
I want to add a new update(new_update) action in my user model of rails which will update a single column in the model. which rest api method I should use in routes file. Should I use put or patch or both.
resources: users do
member do
put 'new_update'
patch 'new_update'
end
Upvotes: 0
Views: 3606
Reputation: 326
If you want to match 100% with the HTTP verb definition.
PUT is supposed to overwrite your targeted resource entirely with the content in the request(all field non present in the request should be set to removed/nullified).
PATCH is supposed to only modify the fields sent in the request.
That being said, most of the time people don't make the difference and use either of them (a lot of people don't even know that there is a PATCH verb) is use PUT with the same behavior as PATCH (since the use case for PUT is quite rare on imo).
Upvotes: 4