资 源 简 介
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 handler
```
package 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 youLoadModule apreq_module modules/mod_apreq2.soLoadModule perl_module modules/mod_perl.so# Load Apache2::RESTPerlModule Apache2: