[Catalyst] Request for comments: model class for REST queries

Christopher Heschong chris at wiw.org
Wed Dec 6 15:08:08 GMT 2006


Hi, I've created a simple library to make calls to REST services, along
with an associated Catalyst model, and wanted to get some feedback.  The
class itself is called CRUST and basically it's just some very simple glue
for URI, LWP, XML::Simple (although any other serialization formatters are
supported). GET and POST are supported of course.

Here's an example of how I might use it to talk to Yahoo! Answers:

  # Create a CRUST model
  package MyApp::Model::Amazon;
  use base 'Catalyst::Model::CRUST';

  __PACKAGE__->config(
    base => 'http://answers.yahooapis.com/AnswersService/V1/',
    query => { appid => 'YahooDemo' }
  );
  1;


  # Meanwhile in a controller nearby
  $c->stash->{answers} = $c->model('YahooAnswers')->get( 'questionSearch',
      query => $c->req->param('query')
  );

  # or
  $c->stash->{answers} = $c->model('YahooAnswers')->get( 'getByCategory',
      category_name => 'Computers & Internet Software'
  );


Does anyone find this useful?  SVN snapshot is available:
  http://svn.screwdriver.net/repos/code/CRUST

Should this sort of thing being uploaded to CPAN?  Anyone want to review
the code beforehand?





More information about the Catalyst mailing list