=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, } }; }
According to http://search.cpan.org/~bobtfish/Catalyst-Action-REST-0.90/lib/Catalyst/Action/REST/ForBrowsers.pm
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, } }; }

In reply to Catalyst::Action::REST::ForBrowsers not detecting browser? by uG

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.