Chris's Wiki :: blog/web/FormsAreAnonymous Commentshttps://utcc.utoronto.ca/~cks/space/blog/web/FormsAreAnonymous?atomcommentsDWiki2011-07-15T13:15:34ZRecent comments in Chris's Wiki :: blog/web/FormsAreAnonymous.From 97.107.130.220 on /blog/web/FormsAreAnonymoustag:CSpace:blog/web/FormsAreAnonymous:9026d7fb47904c0ff2d9ad8d4de7d1d867a45ea0From 97.107.130.220<div class="wikitext"><p>It’s not technically, I think, a REST violation. But it <em>is</em> unwise. Rarely is there any good reason against minting more URIs.</p>
<p>The way I would model this is using <code>DELETE</code> and a <code>PUT</code> to an extra URI. In practice these are <code>POST</code>s, but I use a <a href="http://catalyst.perl.org/">Catalyst</a> plugin that overrides the request method in <code>POST</code> requests based on a special form field.</p>
<p>For deletion I use forms where the checkbox sets not a flag, but that special <code>POST</code> parameter which turns the request into a <code>DELETE</code>. So if the user forgets the checkbox they will just send an empty <code>POST</code> (which is intercepted early in my dispatch, and which is also prevented on the client by Javascript: the submit button is disabled until the box is ticked).</p>
<p>For activation I’d have an extra <code>/activation</code> sub-URI that accepts a <code>PUT</code> of <code>activated=1</code> (or 0) (yes, just the one key). I use <code>PUT</code> for all updates, bonafide <code>POST</code> does entity creation almost exclusively. (I use <code>POST</code> for a handful of other “kick off a process” kind of jobs, such as sending an email, but there are very few of those.) Since the semantics of <code>PUT</code> forbid partial updates I mint a new subresource for each subset of an entity I <em>do</em> want to update partially.</p>
<p>I’ve found that having <code>PUT</code> and <code>DELETE</code> in addition to <code>POST</code> has made things <em>a lot</em> simpler to think about, as there are far fewer ambiguous design choices. That has made the code a lot easier to navigate too, since the structure of controllers is very regular.</p>
<p>(I don’t know how easy this would be to do in Django. If not, why not?)</p>
<p>—<a href="http://plasmasturm.org/">Aristotle Pagaltzis</a></p>
</div>2011-07-15T13:15:34Z