[Catalyst] DELETE through REST and Jemplate

Emmanuel Quevillon tuco at pasteur.fr
Mon Mar 30 15:39:50 BST 2009


J. Shirley wrote:
> On Mon, Mar 30, 2009 at 7:24 AM, Emmanuel Quevillon <tuco at pasteur.fr
> <mailto:tuco at pasteur.fr>> 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 <http://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?
> 
>     Sorry if my question seems stupid, I am a bit lost.
>     If anybody has any clue, very welcome.
> 
>     Regards
>     --
>     -------------------------
>     Emmanuel Quevillon
>     Biological Software and Databases Group
>     Institut Pasteur
>     +33 1 44 38 95 98
>     tuco at_ pasteur dot fr
>     -------------------------
> 
>  
> You didn't include your remove_item method.  Can you post that?
> 
> -J

It is very basic, it took code from Jrock's book :)

sub item_DELETE {

    my($self, $c) = @_;

    my $id = $c->stash()->{id};

    my $set = $c->model('MyAppDB::Item')->find({id => $id});

    if($set){
        $self->status_ok($c,
                         entity => mk_entity($set));
        $set->delete();
    }
    else{
        $self->status_not_found($c,
                                message => "Item not found");
    }
}

-- 
-------------------------
Emmanuel Quevillon
Biological Software and Databases Group
Institut Pasteur
+33 1 44 38 95 98
tuco at_ pasteur dot fr
-------------------------



More information about the Catalyst mailing list