Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

rest modify resource  RSS feed

 
David Spades
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


now, I only want to change age to 35, which method should I use and how should the payload/URL look like to be RESTful?
tried googling but only found endless debates and contradicting blog posts. any consensus on this one yet?
thanks
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the client know the unique identifier of the object you are modifying? If it does then the age modification is idempotent and you are PUTing the modified resource at the url that the client knows about.
 
David Spades
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, but if you use PUT, are you allowed to only send age attribute, or do you need to send the whole citizen object? thanks
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Spades wrote:ok, but if you use PUT, are you allowed to only send age attribute, or do you need to send the whole citizen object? thanks


It's up to how you want to interpret it in the service layer. A wise option is to assume that only the sent fields should be changed because clients usually don't have the full properties of the server resource they are updating. It also reduces payload sizes. That means you need to think about how clients can reset the values if they want to (perhaps send a known default to indicate that). In practice resetting of values doesn't happen that frequently so don't let this exceptional case have more say on your design than the normal cases.
 
David Spades
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see, does the same principle apply for response, i.e. sending partial response? thanks
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Partial responses are normally (as by facebook and google API designs) decided by clients through sending an optional fields parameter which says which fields of the resource should be returned.
In this case the service assumes that the clients wants all fields unless explicitly told to limit through this fields parameter. Applying the same idea for PUTs can have different interpretations. One might say the server must assume that only the fields specified in the PUT payload must be changed. You could also say all the fields specified in the PUT payload must be changed and mean exactly the same thing!
 
David Spades
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
https://twitter.com/fielding/status/275471320685367296

the problem is, the big guy himself said that partial PUT is never RESTful. PATCH is not yet adopted by many web server/ browsers, so what to do?
thanks
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a sense yes, the best case scenario is that the subset of properties that can be updated together have their own payloads so that you are always doing a full upload (albeit on smaller resources). That way the client doesn't need to know all the properties of the resource, just the 'subresource' that it needs to update. It is unlikely that you will be able to finish an application and have adhered to all purist principles, the important thing is to know when you are deviating, why and what the implications would be.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!