Apache2-REST

 view release on metacpan or  search on metacpan

lib/Apache2/REST.pm  view on Meta::CPAN

package Apache2::REST;

use warnings;
use strict;

use APR::Table ();

use Apache2::Request ();
use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::Response ();
use Apache2::RequestUtil ();
use Apache2::Log;

use Apache2::REST::Handler ;
use Apache2::REST::Response ;
use Apache2::REST::Request ;

use Apache2::REST::Conf ;

use Data::Dumper ;

our $VERSION = '0.07';

=head1 NAME

Apache2::REST - Micro framework for REST API implementation under apache2/mod_perl2/apreq2

=head1 VERSION

Version 0.07

=head1 QUICK TUTORIAL

=head2 1. Implement a Apache2::REST::Handler

This module will handle the root resource of your REST API.

   package MyApp::REST::API ;
   use warnings ;
   use strict ;

   # Implement the GET HTTP method.
   sub GET{
       my ($self, $request, $response) = @_ ;
       $response->data()->{'api_mess'} = 'Hello, this is MyApp REST API' ;
       return Apache2::Const::HTTP_OK ;
   }
   # Authorize the GET method.
   sub isAuth{
      my ($self, $method, $req) = @ _; 
      return $method eq 'GET';
   }
   1 ;

=head2 2. Configure apache2

Apache2::REST is a mod_perl2 handler.

In your apache configuration:

   # Make sure you
   LoadModule apreq_module modules/mod_apreq2.so
   LoadModule perl_module modules/mod_perl.so

   # Load Apache2::REST
   PerlModule Apache2::REST 
   # Let Apache2::REST handle the /
   # and set the root handler of the API
   <Location />
      SetHandler perl-script
      PerlSetVar Apache2RESTHandlerRootClass "MyApp::REST::API"
      PerlResponseHandler  Apache2::REST
   </Location>

See L<Apache2::REST::Handler> for  about how to implement a handler.

Then access C<http://yourhost/>. You should see your greeting message from your MyApp::REST::API handler.

See L<Apache2::REST::Overview> for more details about how it works.



( run in 0.917 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )