On 1/1/07, Robert Ian Smit <[EMAIL PROTECTED]> wrote:
> REST gets a lot of press these days, it seems. However, I haven't found > many examples of how it works in practice. It seems that put and delete > methods need to be called via XMLHttpRequest (AJAX). Pylons and some other frameworks can work with browser-unsupported HTTP verbs by using a hidden input field. The formcontents are POSTed to the server as usual, the framework will see the hidden field and translate it to the proper call in the application, i.e.: <input type="hidden" name="_method" value="DELETE" /> Also have a look at the Routes documentation[1] concerning REST. To request a form representation of a resource (for preparing edits that can be PUTted) map.resource from Routes (and others) suggests adding ';edit' to the URL. For instance a request to /foo/1;edit should result in a form. Combined with a hidden "_method" input field it is possible to use RESTful operations with classic POST and redirect interaction between browser and server. No AJAX or any Javascript is required for this. I'd like to add one question of my own. Should there be a "Are you sure you want to delete?" representation added to map.resource? It's easy to add a member but shouldn't the framework offer a convention? [1] http://routes.groovie.org/manual.html#restful-services
Thank. This clarifies a lot for me. I have tried using the map.resource() methods and the hidden field method for performing a delete, for example. Under pylons, does the translation from the hidden field to http method happen before dispatch via routes? It seems like it isn't happening, as when I have html that looks like this: <td><form method="post" action="/talks/1" class="button-to"><div><input onclick="return confirm('Are you sure?');" type="submit" value="Destroy" /></div></form></td> And a map.resource('talk','talks') with a talks.py controller and a delete(self,id) method, I get an error and the method on the debug page says "POST". Any thoughts? Thanks again, Sean --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---