Search code examples
perlrestapache2mod-perl2

What Perl RESTful framework do you recommend?


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?


Solution

  • 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/