Catalyst::Controller::REST implements a mechanism for building RESTful services in Catalyst. It does this by extending the normal Catalyst dispatch mechanism to allow for different subroutines to be called based on the HTTP Method requested, while also transparently handling all the serialization/deserialization for you.

This is probably best served by an example. In the above controller, we have declared a Local Catalyst action on "sub thing", and have used the ActionClass('REST').

Below, we have declared "thing_GET" and "thing_PUT". Any GET requests to thing will be dispatched to "thing_GET", while any PUT requests will be dispatched to "thing_PUT".

Any unimplemented HTTP methods will be met with a "405 Method Not Allowed" response, automatically containing the proper list of available methods. You can override this behavior through implementing a custom thing_not_implemented method.

If you do not provide an OPTIONS handler, we will respond to any OPTIONS requests with a "200 OK", populating the Allowed header automatically.

Any data included in $c->stash->{'rest'} will be serialized for you. The serialization format will be selected based on the content-type of the incoming request. It is probably easier to use the "STATUS HELPERS", which are described below.

The HTTP POST, PUT, and OPTIONS methods will all automatically deserialize the contents of $c->request->body based on the requests content-type header. A list of understood serialization formats is below.

If we do not have (or cannot run) a serializer for a given content-type, a 415 "Unsupported Media Type" error is generated.

Catalyst::Controller::REST will automatically serialize your responses, and deserialize any POST, PUT or OPTIONS requests. It evaluates which serializer to use by mapping a content-type to a Serialization module. We select the content-type based on:

Uses XML::Simple to generate XML output. This is probably not suitable for any real heavy XML work. Due to XML::Simples requirement that the data you serialize be a HASHREF, we transform outgoing data to be in the form of:

Uses a regular Catalyst view. For example, if you wanted to have your text/html and text/xml views rendered by TT:

'text/html' => [ 'View', 'TT' ],
'text/xml' => [ 'View', 'XML' ],

Will do the trick nicely.

By default, Catalyst::Controller::REST will return a 415 Unsupported Media Type response if an attempt to use an unsupported content-type is made. You can ensure that something is always returned by setting the default config option:

__PACKAGE__->config->{'default'} = 'text/x-yaml';

Would make it always fall back to the serializer plugin defined for text/x-yaml.

Since so much of REST is in using HTTP, we provide these Status Helpers. Using them will ensure that you are responding with the proper codes, headers, and entities.

These helpers try and conform to the HTTP 1.1 Specification. You can refer to it at: http://www.w3.org/Protocols/rfc2616/rfc2616.txt. These routines are all implemented as regular subroutines, and as such require you pass the current context ($c) as the first argument.

I have code in production using Catalyst::Controller::REST. That said, it is still under development, and it's possible that things may change between releases. I promise to not break things unneccesarily. :)