[Catalyst] Request for comments: model class for REST queries
Christopher Heschong
chris at wiw.org
Thu Dec 7 20:14:19 GMT 2006
Adam, thanks for the feedback and suggestions! See below for more
comments:
On Dec 7, 2006, at 12:28 PM, Adam Jacob wrote:
> On Wed, Dec 06, 2006 at 10:08:08AM -0500, Christopher Heschong wrote:
>> 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.
>
> My first thought is that you are going to need to support the full
> range
> of HTTP Methods. At the very least, you will need: GET, POST, PUT and
> DELETE. You probably want to support OPTIONS and HEAD as well.
Thanks. There are ->get and ->post methods already, plus ->request
($method, ...) for any other method LWP supports if you need those.
But it's probably a good idea to add them as methods by default.
Although what would you really expect to get back from OPTIONS? I'm
sort of expecting some XML or something back now.
>
>> 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' }
>> );
>
> The query part might be better named "params", since that's what
> Catalyst uses.
Another good point, will fix.
>
>> # Meanwhile in a controller nearby
>> $c->stash->{answers} = $c->model('YahooAnswers')->get
>> ( 'questionSearch',
>> query => $c->req->param('query')
>> );
>
> Ew! Do they really have URLs like questionSearch and getByCategory?
> Very un-RESTful.
(No comment... it's better than Amazon IMHO)
>> 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?
>
> Something like this is both useful and good. I'm not certain what the
> best way to implement it is. I'll try and find some time to look at
> your code soon.
>
> Adam
One thought that crossed my mind was to make methods like:
$c->model('whatever')->get_questionSearch( [params] )
$c->model('whatever')->post_questionSearch( [params] )
or just
$c->model('whatever')->questionSearch( [params] ) #default to GET
instead of what I have now:
$c->model('whatever')->get('questionSearch(params => ...);
$c->model('whatever')->post('questionSearch(params => ...);
A bit of AUTOLOAD should do the trick, but would the above syntax be
better or worse?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2409 bytes
Desc: not available
Url : http://lists.scsys.co.uk/pipermail/catalyst/attachments/20061207/bb60481e/smime-0001.bin
More information about the Catalyst
mailing list