Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

A RESTful API framework

by jeteve (Pilgrim)
on Nov 09, 2009 at 17:00 UTC ( #805964=perlnews: print w/ replies, xml ) Need Help??

Hi fellow monks.

I've just finished writing a new framework that will allow us to implement RESTful API's in a simple and reusable way under apache2/mod_perl2.

Here's the google code page (the upload to CPAN is ongoing): apache2rest

This is a beta pre-release, so don't expect a full comprehensive documentation written in perfect english.

I'd like very much to have your suggestions, remarks or patches to make this module better.

UPDATE I started to write a Cook book with the most frequent questions: Apache2::REST Cookbook

Cheers!

Comment on A RESTful API framework
Re: A RESTful API framework
by Arunbear (Parson) on Nov 09, 2009 at 22:04 UTC
    Could you give examples of how to implement PUT and DELETE requests? Thanks.
      Sure, it's exactly like implementing GET,

      In your subclass of Apache2::REST::Handler, just implement DELETE or PUT:

      sub PUT{ my ( $self , $req , $resp ) = @_; .. Do put something in this resource .. .. Fill resp if necessary .. .. Return the appropriate http code if( $somethingWentWrong ){ return Apache2::Const::HTTP_BAD_REQUEST ; } # else it's ok return Apache2::Const::HTTP_OK ; }
Re: A RESTful API framework
by ctilmes (Priest) on Nov 10, 2009 at 18:46 UTC
    I like some of the things that Catalyst::Controller::REST does, you might take a look at it -- it follows a similar approach to what you are proposing, but in the context of Catalyst.

    In particular, it unpacks the supplied content (if you want) based on the format specified by the "Content-Type" header, and serializes your output data structure. (It uses Content-Type for that too -- I think it should use "Accept" for that.)

    Your GET/PUT/POST handler doesn't have to deal with that at all, but the user can supply input in whatever format they want: XML, YAML, JSON, etc. and consume your results however they want. The perl handler can just deal with native perl data structures.

      Yep, that's interesting.

      I'm planning to allow you to plugin your own crafted Apache2::Request subclass in the system, so if you need a specific deserialization, you'd be able to implement it yourself.

Re: A RESTful API framework
by ctilmes (Priest) on Nov 10, 2009 at 20:17 UTC
    I like your "TIMTOWTDI" with the "fmt=json" parameter in the URL and "GET .../foo.json" extension. Just also get it from the standard HTTP "Accept: application/json" header.
      Thanks for the idea.

      I'm not sure how to implement it though. Should I assume that API developers will tell their API users to specify just one pure MIME type in their Accept header?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlnews [id://805964]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2014-10-02 10:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (52 votes), past polls