Skip to content

Add config.default_method_for_update to support PATCH#5130

Merged
fxn merged 1 commit intorails:masterfrom
dlee:revised_patch_verb
Feb 22, 2012
Merged

Add config.default_method_for_update to support PATCH#5130
fxn merged 1 commit intorails:masterfrom
dlee:revised_patch_verb

Conversation

@dlee
Copy link
Copy Markdown
Contributor

@dlee dlee commented Feb 22, 2012

PATCH is the correct HTTP verb to map to the #update action. The
semantics for PATCH allows for partial updates, whereas PUT requires a
complete replacement.

Changes:

  • adds config.default_method_for_update you can set to :patch
  • optionally use PATCH instead of PUT in resource routes and forms
  • adds the #patch verb to routes to detect PATCH requests
  • adds #patch? to Request
  • changes documentation and comments to indicate support for PATCH

This change maintains complete backwards compatibility by keeping :put
as the default for config.default_method_for_update.

(Continuation of Issue #505)

Update: as rinaldifonseca pointed out, there was a typo in the pull request message that said "HTML verb" instead of "HTTP verb".

PATCH is the correct HTML verb to map to the #update action. The
semantics for PATCH allows for partial updates, whereas PUT requires a
complete replacement.

Changes:
* adds config.default_method_for_update you can set to :patch
* optionally use PATCH instead of PUT in resource routes and forms
* adds the #patch verb to routes to detect PATCH requests
* adds #patch? to Request
* changes documentation and comments to indicate support for PATCH

This change maintains complete backwards compatibility by keeping :put
as the default for config.default_method_for_update.
@ghost ghost assigned fxn Feb 22, 2012
@fxn
Copy link
Copy Markdown
Member

fxn commented Feb 22, 2012

Good patch.

fxn added a commit that referenced this pull request Feb 22, 2012
Add config.default_method_for_update to support PATCH
@fxn fxn merged commit 7f2548e into rails:master Feb 22, 2012
@arunagw arunagw mentioned this pull request Feb 22, 2012
@markiz
Copy link
Copy Markdown

markiz commented Feb 26, 2012

@rinaldifonseca yep.
Actually, it's all over commit, worth fixing, if it isn't already.

@dlee
Copy link
Copy Markdown
Contributor Author

dlee commented Feb 26, 2012

@rinaldifonseca Yeah, that's a typo on my part.

@markiz I don't see the "HTML"-for-"HTTP" typo in the code of the commit. Can you point out where?

@ncreuschling
Copy link
Copy Markdown
Contributor

I quote your original pull request:

PATCH is the correct HTML verb to map to the #update action.

@markiz
Copy link
Copy Markdown

markiz commented Feb 26, 2012

@dlee
Mea culpa, it's used a couple of time in the responder code, in context of "HTML request" meaning "request for HTML format". Sorry for misreading.

@dlee
Copy link
Copy Markdown
Contributor Author

dlee commented Feb 26, 2012

@ncreuschling Thanks, fixed the original pull request as well.

@stevegraham
Copy link
Copy Markdown
Contributor

Where does it say in the HTTP spec that PUT mandates a complete replacement? Hint: it doesn't.

op will surely deliver

@fxn
Copy link
Copy Markdown
Member

fxn commented Feb 27, 2012

@stevegraham please see the discussion in #505, in particular interpretations of quotes of the spec. And most importantly the quotes from Roy Fielding that helped to definitely lean the discussion.

@stevegraham
Copy link
Copy Markdown
Contributor

@fxn i think i should know about #505 as i participated extensively in the comments.

why is roy fielding's opinion more relevant than the other 6 authors of rfc2616? presumably because he is the father of REST, but why not ask tim berners-lee as he is the father of the WWW, surely more authoritative? (tongue firmly in cheek). regardless, why is something fielding says in a blog post or mailing list more authoritative than a rfc?

should a spec need interpretation? i don't think so. a specification is by definition a precise description of requirements.

and can someone actually show a concrete example of a problem this solves?

@fxn
Copy link
Copy Markdown
Member

fxn commented Feb 27, 2012

@stevegraham I can't believe we are onto this again. I'll try to summarize. A specification uses natural language and thus it is subject to the ambiguities of natural language. A RFC is not expressed in the formal language of mathematical logic, so you will agree with me certainly that there may be room for interpretation in some places. This is a case in point.

RFC 2616 says "The PUT method requests that the enclosed entity be stored under the supplied Request-URI.". Now almost everyone on planet Earth reads there creation or replacement. Since this is formulated in English some minority (to which you seem to belong) argue that it is ambiguous and that your interpretation leaves room for partial updates in that sentence.

OK, a way to settle that? Have the person whose name appears first in the list of authors of RFC 2616 tell us what it means. It means creation or replacement. Period (as he puts it).

@stevegraham
Copy link
Copy Markdown
Contributor

@fxn you can't believe that we're onto this again? frankly neither can i.

the total amount of people interested in this pull request and having read the passage "The PUT method requests that the enclosed entity be stored under the supplied Request-URI." is far less than "everyone on planet earth", probably < 10 in reality. please spare me your fallacious arguments.

also, my position does not rely on the ambiguity of the spec whereas your position in fact does. 2616 is very clear in that "HTTP/1.1 does not define how a PUT method affects the state of an origin server" how much more clear does this have to be? partial updates are allowed.

and i ask again WHAT PROBLEM DOES THIS SOLVE?

@stevegraham
Copy link
Copy Markdown
Contributor

i just noticed the fielding commentary that @steveklabnik posted in #505 (grep "game over"). that's the first time i have seen fielding specifically address this issue, rather than have tangential comments of his twisted to fit an argument. i'm happy that the supposed ambiguity has been addressed directly, although i do still think the wording is confusing and could do with being clearer. taking fielding's comments on board, rfc2616 contradicts itself.

@fxn
Copy link
Copy Markdown
Member

fxn commented Feb 27, 2012

@stevegraham so from "HTTP/1.1 does not define how a PUT method affects the state of an origin server" you infer partial updates are allowed? Are you serious man? Steve, not me, Roy Fielding is telling your reading of the spec is wrong.

Please read rest-discuss, please read O'Reilly's book on REST, and have a pulse about how people think what's PUT. There's consensus about the meaning of PUT. That's my sample, not the people in the PR.

The problem this solves is to ease users of Ruby on Rails to follow HTTP semantics, now it's possible but the design should favor PATCH over PUT due to practical needs of most web applications.

@fxn
Copy link
Copy Markdown
Member

fxn commented Feb 27, 2012

@stevegraham ah, you hadn't seen that one! OK, no prob.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants