[Catalyst] DELETE through REST and Jemplate

Lee Aylward lee at laylward.com
Wed Apr 1 23:21:58 BST 2009


On Mon, Mar 30, 2009 at 04:24:42PM +0200, Emmanuel Quevillon wrote:
> Hi,
> 
> I am playing with REST and Jemplate from the great Tuts from JRock's
> book.
> However, I am facing a problem. I understand well how to retrieve
> data from a REST url and playing Ajax with it, by a GET method.
> However, I don't know how to change the method to DELETE from a
> simple link like:
> 
> test.js contains:
> 
> function remove_item(id){
>  Jemplate.process('test.tt2',
> 		  '[% Catalyst.uri_for("/rest/item/") %]'+id,
> 		  '#_item');
> }
> 
> template test.tt2:
> 
> <a href="#" onclick="remove_item('[% item.id %]'); return
> false;">Remove item</a>
> 
> If I code my template like this, it just do a GET request.
> How can I introduce DELETE method  to tell REST API to delete my
> item id?
> 

As has already been mentioned, you'll have to use a seperate javascript
library to make your requests, since Jemplate only supports GET. Be
careful when choosing a javascript library. I recently tried to use
prototype.js to make some PUT and DELETE requests. After investigating,
I discovered that prototype.js does not support some HTTP methods, and
converts them to a POST with an added "_method" parameter that matches
the method you wanted to use. I believe they do this because at some
point not all browsers supported alternative HTTP methods over
XMLHTTPRequest.

-- 
Lee Aylward



More information about the Catalyst mailing list