Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

Error in subclassing Catalyst::Controller::DBIC::API::REST

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


amiribarksdale at gmail

Jun 23, 2009, 5:39 PM

Post #1 of 4 (811 views)
Permalink
Error in subclassing Catalyst::Controller::DBIC::API::REST

I have a controller inheriting from a ControllerBase class that contains
the following:

package RestTest::ControllerBase::REST;

use strict;
use warnings;
use base qw/Catalyst::Controller::DBIC::API::REST/;

sub create :Private {
my ($self, $c) = @_;
$self->next::method($c);
if ($c->stash->{created_object}) {
%{$c->stash->{response}->{new_object}} =
%$c->stash->{created_object}->get_columns;
}
}

1;


All the ControllerBase does is stash that object on create requests. I
was following lukes's example at
http://search.cpan.org/~lsaunders/Catalyst-Controller-DBIC-API-1.003000/lib/Catalyst/Controller/DBIC/API.pm#EXTENDING.
The relevant part of the controller is:


package RestTest::Controller::API::REST::Artist;

use strict;
use warnings;
use base qw/RestTest::ControllerBase::REST/;
use JSON::Syck;

__PACKAGE__->config(
action => { setup => { PathPart => 'artist',
Chained => '/api/rest/rest_base' } },
...
);


Now for the problem. When I go to test this:

my $mech = Test::WWW::Mechanize::Catalyst->new;
ok(my $schema = DBICTest->init_schema(), 'got schema');

my $req = GET("http://localhost/api/rest/artist/list", {
}, 'Accept' => 'text/x-json' );
$mech->request($req);
cmp_ok( $mech->status, '==', 200, 'open attempt okay' );


I get the error:

'Method GET not implemented for http' =>
'//localhost/api/rest/artist/api/rest/artist/object'

Somehow my request path gets all messed up. I dumped out the $mech, and it tells
me that $mech->base is indeed what I put. So is $mech->redirected_uri.



Amiri

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


alexander.hartmaier at t-systems

Jun 24, 2009, 5:33 AM

Post #2 of 4 (723 views)
Permalink
Re: Error in subclassing Catalyst::Controller::DBIC::API::REST [In reply to]

Please provide us with the debug output of your cat app at startup.
Have you tried removing sub create?
Also look at the RestTest app used for the tests to find possible bugs
in your code.

Am Mittwoch, den 24.06.2009, 02:39 +0200 schrieb Amiri Barksdale:
> I have a controller inheriting from a ControllerBase class that contains
> the following:
>
> package RestTest::ControllerBase::REST;
>
> use strict;
> use warnings;
> use base qw/Catalyst::Controller::DBIC::API::REST/;
>
> sub create :Private {
> my ($self, $c) = @_;
> $self->next::method($c);
> if ($c->stash->{created_object}) {
> %{$c->stash->{response}->{new_object}} =
> %$c->stash->{created_object}->get_columns;
> }
> }
>
> 1;
>
>
> All the ControllerBase does is stash that object on create requests. I
> was following lukes's example at
> http://search.cpan.org/~lsaunders/Catalyst-Controller-DBIC-API-1.003000/lib/Catalyst/Controller/DBIC/API.pm#EXTENDING.
> The relevant part of the controller is:
>
>
> package RestTest::Controller::API::REST::Artist;
>
> use strict;
> use warnings;
> use base qw/RestTest::ControllerBase::REST/;
> use JSON::Syck;
>
> __PACKAGE__->config(
> action => { setup => { PathPart => 'artist',
> Chained => '/api/rest/rest_base' } },
> ...
> );
>
>
> Now for the problem. When I go to test this:
>
> my $mech = Test::WWW::Mechanize::Catalyst->new;
> ok(my $schema = DBICTest->init_schema(), 'got schema');
>
> my $req = GET("http://localhost/api/rest/artist/list", {
> }, 'Accept' => 'text/x-json' );
> $mech->request($req);
> cmp_ok( $mech->status, '==', 200, 'open attempt okay' );
>
>
> I get the error:
>
> 'Method GET not implemented for http' =>
> '//localhost/api/rest/artist/api/rest/artist/object'
>
> Somehow my request path gets all messed up. I dumped out the $mech, and it tells
> me that $mech->base is indeed what I put. So is $mech->redirected_uri.
>
>
>
> Amiri
>
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/
--
LG Alex


*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


felliott at virginia

Jun 24, 2009, 6:00 AM

Post #3 of 4 (720 views)
Permalink
Re: Error in subclassing Catalyst::Controller::DBIC::API::REST [In reply to]

Hey Amiri,

> Now for the problem. When I go to test this:
>
> my $mech = Test::WWW::Mechanize::Catalyst->new;
> ok(my $schema = DBICTest->init_schema(), 'got schema');
>
> my $req = GET("http://localhost/api/rest/artist/list", {
> }, 'Accept' => 'text/x-json' );
> $mech->request($req);
> cmp_ok( $mech->status, '==', 200, 'open attempt okay' );


I just finished building some code around C::C::DBIC::API and ran
into something similar. I'm assuming in this test that you are trying
to get a list of all artists. If so, you should make a GET request
against http://localhost/api/rest/artist. In a REST controller,
artist/list would be asking for the artist whose id is 'list'.
C::C::DBIC::API also doesn't support GET on an individual object out
of the box, but it is easy to add. Just add

sub object_GET :Private {}

in RestTest::ControllerBase::REST. The rest of the code is already
there to retrieve the object and serialize it.

Cheers,
Fitz



_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


luke.saunders at gmail

Jun 24, 2009, 7:01 AM

Post #4 of 4 (722 views)
Permalink
Re: Error in subclassing Catalyst::Controller::DBIC::API::REST [In reply to]

On Wed, Jun 24, 2009 at 3:00 PM, Fitz Elliott<felliott [at] virginia> wrote:
> Hey Amiri,
>
>> Now for the problem. When I go to test this:
>>
>> my $mech = Test::WWW::Mechanize::Catalyst->new;
>> ok(my $schema = DBICTest->init_schema(), 'got schema');
>>
>> my $req = GET("http://localhost/api/rest/artist/list", {
>> }, 'Accept' => 'text/x-json' );
>> $mech->request($req);
>> cmp_ok( $mech->status, '==', 200, 'open attempt okay' );
>
>
> I just finished building some code around C::C::DBIC::API and ran into
> something similar. I'm assuming in this test that you are trying to get a
> list of all artists. If so, you should make a GET request against
> http://localhost/api/rest/artist. In a REST controller, artist/list would
> be asking for the artist whose id is 'list'. C::C::DBIC::API also doesn't
> support GET on an individual object out of the box, but it is easy to add.
> Just add
>
> sub object_GET :Private {}
>
> in RestTest::ControllerBase::REST. The rest of the code is already there to
> retrieve the object and serialize it.

As Fitz has said above - if you want to use REST then you have to make
the GET request to just /api/rest/artist. However if you would prefer
to to the url /api/rest/artist/list then that's more RPC style and so
you'd have to be subclassing Catalyst::Controller::DBIC::API::RPC.

I'm interested in the
'//localhost/api/rest/artist/api/rest/artist/object' weirdness. Is
that specific to running under Test::WWW::Mechanize::Catalyst? Maybe
try starting a server in debug mode and then specify
CATALYST_SERVER=http://localhost:3000 before running the test to see
how that's getting dispatched.

Cheers,
Luke.

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.