you can also just to do:

  <Location /parts>
    SetHandler modperl
    PerlResponseHandler My::Parts::Handler 
  </Location>
 
And handle the validation of the rest of the URL within your ResponseHandler.  
You could implement as much depth below /parts as you want.  api calls you'll 
probably want to use are

$r->location (in this case, would return /parts)
$r->uri (the actual URI requested)

i have a number of Handlers that aren't doing REST, but do work on the same 
sort of principle.  I use this utility function to parse take a request object 
and give me an array of all it's bits.  it compacts multiple /'s into a single 
one because that's what apache would do with them by default.  I'm pretty sure 
that Apache::Dispatch does something very similar to this.

sub parse_request {
    my $r = shift;
    
    my $uri = $r->uri;
    #
    # compact /'s
    #
    $uri =~ s|\/+|\/|gi;
    #
    # strip the location off the front of the uri
    #
    my $location = $r->location;
    $uri =~ s|^$location/?||;
    #
    # split what's left
    #
    my @split_uri = split '/', $uri;
    #
    # return a reference to the array
    #
    return [EMAIL PROTECTED];
}

Adam

-----Original Message-----
From: Dami Laurent (PJ) [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, November 27, 2007 1:05 PM
To: modperl@perl.apache.org
Subject: RE: REST

 

>-----Message d'origine-----
>De : Beginner [mailto:[EMAIL PROTECTED] 
>Envoyé : mardi, 27. novembre 2007 18:49
>À : modperl@perl.apache.org
>Objet : REST
>
>Hi,
>
>I hope this isn't a dumb question. 
>
>I want to try and create a small REST style installation and was 
>considering how to overcome the problem of urls in the form
>
>http://www.myfactory.com/parts/1234
>
>The resource after /parts could in theory be any number but you would 
>not want to have a <Location> for each part that existed. Rather 
>you'd want the handler responsible for /parts to check your db and 
>return either content or 400. 
>
>On the face of it this is the sort of thing mod_perl should excel at. 
>Does it? Can you intercept requests like this one above? Which API 
>methods should I be looking at?
>
>TIA,
>Dp.

This is the sort of things that Catalyst would excel at, especially
if you have several nesting levels (i.e. parts/1234/subpart/567/form).
See Catalyst doc at  
http://search.cpan.org/~jrockway/Catalyst-Manual-5.701003/lib/Catalyst/Manual/Intro.pod.

But if you don't need that complexity, you can easily do it in mod_perl :
configure Apache with something like 
  <LocationMatch "/parts/\d+$">
    SetHandler modperl
    PerlResponseHandler My::Parts::Handler 
  </LocationMatch>

and then have your module My::Parts::Handler parse the URL and get to the part 
number.

Good luck, L. Dami

Reply via email to