|
Project Information
Featured
Downloads
Links
|
Apache2::REST provides a simple and flexible micro-framework which allows developers to implement their application RESTful's API in Perl, using apache2 and mod_perl2/mod_apreq2. Find the code and more documentation at CPAN Here's a quick tutorial: 1. Install it$ cpan -i Apache2::REST 2. Write your first API root handlerpackage MyApp::REST::API ;
use warnings ;
use strict ;
use base qw/Apache2::REST::Handler/ ;
# 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 ;3. Configure apache# 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> 4. Access your brand new APIAt http://yourhost/ Now read the CookBook and perldoc Apache2::REST to go further. |