[Catalyst] Catalyst::Helper::Controller::Scaffold::REST and
corresponding ajax Class::DBI-like module
Scotty Allen
lists at scottyallen.com
Fri Nov 4 09:58:30 CET 2005
Hi all,
I've been doing some AJAX work with Catalyst recently, and realized I
wanted the ability to push the power of Class::DBI and Catalyst all the
way to the logical edge of my application, the browser. Thus, I've put
together two modules to address this.
The first, Catalyst::Helper::Controller::Scaffold::REST provides a
simple REST interface for a CDBI class. HTTP GET, POST, PUT, and DELETE
on a url endpoint are mapped onto retrieve, update, insert and delete in
the CDBI class.
You can download it at:
http://scottyallen.com/perl/Catalyst-Helper-Controller-Scaffold-
REST-0.02.tar.gz
I've held out on uploading to CPAN until I got a bit of feedback,
particularly as this will be my first CPAN release.
Also, I've put together a nifty little javascript library, which
provides a Class::DBI-like AJAX interface to the REST interface. It's
meant to dovetail with the REST scaffolding above. You can do things
like:
// Basic class setup
Music.Artist = Class.create();
Music.Artist.extend(JSDBI);
Music.Artist.prototype = (new JSDBI()).extend( {
initialize: function () {
},
});
Music.Artist.fields(['artistid', 'name']);
Music.Artist.url('http://someserver/rest/artist');
Music.Artist.elementTag('artist'); //optional
// In the calling code
var artist = Music.Artist.insert({name: 'Billy'});
var artistid = artist.id();
artist = Music.Artist.retrieve(artistid);
document.write("name: "+artist.name());
artist.name('Fred');
artist.update();
artist.destroy();
It can be found at http://scottyallen.com/code/jsdbi.js
Feedback on either module would be more than welcome.
-Scotty
--
The future is already here. It's just not very evenly distributed yet.
- William Gibson
More information about the Catalyst
mailing list