【发布时间】:2014-01-30 05:01:02
【问题描述】:
我想通过 Catalyst 编写 restful api,并用于这个 [Catalyst::Controller::REST][1]。
我已经写了那个代码。
package addressbook::Controller::REST;
use strict;
use warnings;
use base qw(Catalyst::Controller::REST);
sub user :Local :ActionCLass('REST') :Args(1){
my( $self, $c, $id ) = @_;
$c->stash( id => $id );
}
# Get user
sub user_GET {
my ( $self, $c ) = @_;
my $user = $c->model('DB::User')->find( { id => $c->stash->{id} } );
if ( $user ){
$self->status_ok($c, entity => { firstname => $user->firstname } );
}
else {
$self->status_not_found($c, message => 'No matching user');
}
}
__PACKAGE__->config(default => 'text/x-json');
1;
然后我运行服务器,转到 localhost:3000/rest/user/1(我有那个 id 的用户)并获取
找不到您的客户端支持的 Content-Type。
我尝试设置 PACKAGE->config application/json, text/xml, text/html, text/x-yaml ...但没有帮助。
有什么想法吗?
谢谢。
【问题讨论】: