uG has asked for the wisdom of the Perl Monks concerning the following question:
According to http://search.cpan.org/~bobtfish/Catalyst-Action-REST-0.90/lib/Catalyst/Action/REST/ForBrowsers.pm=head2 user =cut sub user :Local :ActionClass('REST::ForBrowsers') Args(1) { my($self, $c, $id) = @_; $c->stash(id => $id); } =head2 user_GET Handle GET requests. =cut sub user_GET_html : Private { my($self, $c) = @_; my $id = $c->stash->{id}; my $user = $c->model('ForumDB::User')->find({ id => $id }); if($user) { $self->edit_form->process( item => $user, params => $c->request->parameters, ); $self->status_ok($c, entity => { form => $self->edit_form->ren +der }); } else { $self->status_not_found($c, message => 'No matching user found +'); } } sub user_GET : Private { my($self, $c) = @_; my $id = $c->stash->{id}; my $user = $c->model('ForumDB::User')->find({ id => $id }); if($user) { $self->status_ok($c, entity => mk_user_entity($user)); } else { $self->status_not_found($c, message => 'No matching user found +'); } } sub mk_user_entity { my $user = shift; return { user => { id => $user->id, username => $user->username, password => $user->password, } }; }
sub foo :Local :ActionClass('REST::ForBrowsers') { ... do setup for HTTP method specific handlers ... } sub foo_GET : Private { ... do something for GET requests ... } sub foo_GET_html : Private { ... do something for GET requests from browsers ... } sub foo_PUT : Private { ... do something for PUT requests ... }
Yet when I make an ajax call to my REST controller from my browser it still calls user_GET instead of user_GET_html Am I misunderstanding what this ActionClass does?
Here is the entire controller, just in case...
package Forum::Controller::REST; use Moose; use namespace::autoclean; __PACKAGE__->config(default => 'application/json'); use Forum::Form::User::Edit; BEGIN {extends 'Catalyst::Controller::REST'; } has 'edit_form' => ( isa => 'Forum::Form::User::Edit', is => 'rw', lazy => 1, default => sub { Forum::Form::User::Edit->new }, ); =head1 NAME Forum::Controller::REST - REST Controller =head1 DESCRIPTION REST Controller. =head1 METHODS =cut =head2 begin =cut sub auto : ActionClass('Deserialize') { my($self, $c) = @_; my $username = $c->req->header('X-Username'); my $password = $c->req->header('X-Password'); if( !$c->user && !$c->authenticate({username => $username, passwor +d => $password})) { $c->res->status(403); #forbidden $c->res->body("You are not authorized to use the REST API."); $c->detach; } } =head2 user =cut sub user :Local :ActionClass('REST::ForBrowsers') Args(1) { my($self, $c, $id) = @_; $c->stash(id => $id); } =head2 user_GET Handle GET requests. =cut sub user_GET_html : Private { my($self, $c) = @_; my $id = $c->stash->{id}; my $user = $c->model('ForumDB::User')->find({ id => $id }); if($user) { $self->edit_form->process( item => $user, params => $c->request->parameters, ); $self->status_ok($c, entity => { form => $self->edit_form->ren +der }); } else { $self->status_not_found($c, message => 'No matching user found +'); } } sub user_GET : Private { my($self, $c) = @_; my $id = $c->stash->{id}; my $user = $c->model('ForumDB::User')->find({ id => $id }); if($user) { $self->status_ok($c, entity => mk_user_entity($user)); } else { $self->status_not_found($c, message => 'No matching user found +'); } } sub mk_user_entity { my $user = shift; return { user => { id => $user->id, username => $user->username, password => $user->password, } }; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Catalyst::Action::REST::ForBrowsers not detecting browser?
by Khen1950fx (Canon) on Apr 18, 2011 at 10:14 UTC |