Hi I'm looking for a Perl RESTful framework that have to :
- work under apache2/mod_perl2
- be simple
- be elegant
- be light
- be flexible
Am I just dreaming or can I avoid the 'Roll our own' approach?
What framework would you recommend?
Hi I'm looking for a Perl RESTful framework that have to :
Am I just dreaming or can I avoid the 'Roll our own' approach?
What framework would you recommend?
I think you will find that Squatting
ticks all those boxes!
I've written quite a few small RESTful apps with it. Its ideally suited for this and its been a pleasure to work with.
Here are some more links:
Here is a simple "hello world!" example:
use strict;
use warnings;
{
package Simple;
use base 'Squatting';
}
{
package Simple::Controllers;
use Squatting ':controllers';
our @C = (
C(
Index => [ '/' ],
get => sub {
my ($self) = @_;
my $v = $self->v;
$v->{hello} = 'Hello World!';
$self->render( 'hello' );
},
),
);
}
{
package Simple::Views;
use Squatting ':views';
use HTML::AsSubs;
our @V = (
V( 'html',
layout => sub {
my ($self, $v, @yield) = @_;
html(
head( title('Simple web app') ),
body( @yield ),
)->as_HTML;
},
hello => sub {
my ($self, $v) = @_;
p( $v->{hello} );
},
),
);
}
Save above as Simple.pm in relevant place and make sure the following is in your Apache config:
<Perl>
use Simple 'On::MP20';
Simple->init
</Perl>
<Location />
SetHandler perl-script
PerlHandler Simple->mp20
</Location>
And away you go!
While here I would also give a passing mention to a couple of other frameworks which should fit the bill:
I say "passing mention" because I haven't used either of these and I'm not sure if either work (out of the box) with mod_perl2. Still with PSGI / Plack
just around the corner this wouldn't be an issue for too long ;-)
/I3az/
Dancer is pretty well documented and trustable if you look at the test suite: ~500 tests that cover more than 80% of the source tree.
It's PSGI/Plack compliant and has few dependencies. The version 1.0 should be released very soon (maybe this weekend).
See the dancer website to stay tuned.
Another to consider would be Mojolicious which allows both writing and testing RESTful APIs in a very straightforward way.
My favorite Perl web application framework is CGI::Application. It is very lightweight (a single base class that you can inherit from) and does the bare minimum necessary to handle the repetitive tasks of web app programming and otherwise stay out of your way. You can use it in a formal MVC design, or do things more ad hoc if that's what you want.
It has a simple plugin architecture, allowing you to easily add support for Template Toolkit (HTML::Template is supported out of the box) sessions, authentication, JSON, streaming, and so on.
Finally, for creating REST-like friendly URLs, there is the excellent CGI::Application::Dispatch, which gives you a powerful rules-based engine for URL-based dispatch.
Also, despite its name, it works seamlessly under mod_perl 1 and 2.
I think you will find that Squatting
ticks all those boxes!
I've written quite a few small RESTful apps with it. Its ideally suited for this and its been a pleasure to work with.
Here are some more links:
Here is a simple "hello world!" example:
use strict;
use warnings;
{
package Simple;
use base 'Squatting';
}
{
package Simple::Controllers;
use Squatting ':controllers';
our @C = (
C(
Index => [ '/' ],
get => sub {
my ($self) = @_;
my $v = $self->v;
$v->{hello} = 'Hello World!';
$self->render( 'hello' );
},
),
);
}
{
package Simple::Views;
use Squatting ':views';
use HTML::AsSubs;
our @V = (
V( 'html',
layout => sub {
my ($self, $v, @yield) = @_;
html(
head( title('Simple web app') ),
body( @yield ),
)->as_HTML;
},
hello => sub {
my ($self, $v) = @_;
p( $v->{hello} );
},
),
);
}
Save above as Simple.pm in relevant place and make sure the following is in your Apache config:
<Perl>
use Simple 'On::MP20';
Simple->init
</Perl>
<Location />
SetHandler perl-script
PerlHandler Simple->mp20
</Location>
And away you go!
While here I would also give a passing mention to a couple of other frameworks which should fit the bill:
I say "passing mention" because I haven't used either of these and I'm not sure if either work (out of the box) with mod_perl2. Still with PSGI / Plack
just around the corner this wouldn't be an issue for too long ;-)
/I3az/
Catalyst is a MVC framework that you can use to make Restfull services
EDIT: - The "new" frameworks I said are the ones that have good test frameworks to use (like rails/spring/Seam, with catalyst it is not easy to do tests besides the normal unit tests) and also a lot of developers working to build applications to them (the community around these frameworks are far more active). That's why I dont think Catalyst is really flexible too.
I finally rolled my own pure mod_perl2 RESTful API dedicated framework: http://code.google.com/p/apache2rest/
Nothing is built-in except the essential. The rest is extensible (or will be). I had a look at all your suggestions, and they all seem to address too many things (DBI management, ORM, template engine, embedded server...).
That's why I wrote this one. I hope you'll find it useful.
Sorry about answering a bit late, but I described a REST framework in link text which has worked well for me. It makes adding new resources very simple; I barely have to write more than the resource-specific business logic; the framework takes care of the rest.
© 2022 - 2024 — McMap. All rights reserved.