What Perl RESTful framework do you recommend? [closed]
Asked Answered
N

8

20

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?

Nicaea answered 4/11, 2009 at 17:30 Comment(0)
A
7

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/

Alchemize answered 4/11, 2009 at 18:57 Comment(0)
P
16

I've used Dancer (github) for some smaller projects of mine. It's very elegant and very easy to get things done quickly with. It was inspired by the Ruby framework Sinatra.

It's as easy as:

#!/usr/bin/env perl
use Dancer;

get '/' => sub {
    'Hello world!'
};

dance;
Perri answered 5/11, 2009 at 12:7 Comment(0)
M
9

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.

Mendenhall answered 5/11, 2009 at 16:43 Comment(0)
R
8

Another to consider would be Mojolicious which allows both writing and testing RESTful APIs in a very straightforward way.

Reflection answered 5/11, 2009 at 10:28 Comment(0)
L
7

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.

Laudable answered 4/11, 2009 at 18:22 Comment(0)
A
7

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/

Alchemize answered 4/11, 2009 at 18:57 Comment(0)
F
4

Catalyst is a MVC framework that you can use to make Restfull services

  • It runs under apache2/mod_perl2
  • It is simple and elegant but IMHO not as much as most of the "new" MVC frameworks
  • Yeah .. it is light.
  • Dont think it is really flexible .. :( ..

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.

Frater answered 4/11, 2009 at 17:39 Comment(9)
Thx. What are the "new" MVC frameworks you're referring to?Nicaea
I edited the poThink that would be enough to explainFrater
There's something wrong with your perception of Catalyst then. It's probably the most flexible of all of the various web frameworks out there. And I'm not sure why you think it's hard to test.Pyrenees
I dont't think it is hard to test... I just think that the test frameworks you have are far away from a RSpec or even JUnit/Testng.Frater
Catalyst, and in fact, most of the perl community relies on the ample test frameworks that come from Test::Builder, Test::Harness, and Test::More lineages. For functional testing of websites, there's Test::WWW::Selenium for the Selenium users among us, or for simpler non-ajaxy websites, Test::WWW::Mechaninze. All of these interfaces can then be layered inside an object oriented testing skeleton with classes like Test::Class, a fantastic xunit style testing framework. I'm not exactly sure what testing frameworks you're looking for, or if you're just not familiar with what's out there.Trench
I'm not sure why you would not suggest Catalyst, it is very flexable, and with the move to Moose, is getting even more so. With Catalyst you can also build REST services really easily. See: search.cpan.org/~bobtfish/Catalyst-Action-REST-0.78/lib/…. As for testing goes, like the rest of Perl there is a lot of testing capabailty build into Catalyst. Take a look at search.cpan.org/~flora/Catalyst-Runtime-5.80013/lib/Catalyst/… and related modules. All in all I would say catalyst is a good choice.Matronna
+1 for Catalyst, but -1 for misplaced comment about flexibility/testability.Zone
I don't think I've ever heard anyone call Catalyst "lightweight" before - even without the addition of Moose, it's long been CPAN's poster child for massive dependency chain horror stories. (And, if someone's complaining about dependency chains in something other than Catalyst, it's probably Moose they're complaining about, so Moosifying Catalyst won't help with that.)Reflection
Indeed, the list of the Heavy 100 on CPAN is essentially a list of Catalyst applications. The others are monster bundles of modules which probably shouldn't be counted on the list IMO.Occiput
N
2

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.

Nicaea answered 9/11, 2009 at 17:51 Comment(0)
E
0

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.

Extinct answered 2/6, 2010 at 2:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.