2 Catalyst::Action::REST - Automated REST Method Dispatching
5 sub foo :Local :ActionClass('REST') {
6 ... do setup for HTTP method specific handlers ...
10 ... do something for GET requests ...
13 # alternatively use an Action
14 sub foo_PUT : Action {
15 ... do something for PUT requests ...
19 This Action handles doing automatic method dispatching for REST
20 requests. It takes a normal Catalyst action, and changes the dispatch to
21 append an underscore and method name. First it will try dispatching to
22 an action with the generated name, and failing that it will try to
23 dispatch to a regular method.
25 For example, in the synopsis above, calling GET on "/foo" would result
26 in the foo_GET method being dispatched.
28 If a method is requested that is not implemented, this action will
29 return a status 405 (Method Not Found). It will populate the "Allow"
30 header with the list of implemented request methods. You can override
31 this behavior by implementing a custom 405 handler like so:
33 sub foo_not_implemented {
34 ... handle not implemented methods ...
37 If you do not provide an _OPTIONS subroutine, we will automatically
38 respond with a 200 OK. The "Allow" header will be populated with the
39 list of implemented request methods.
41 It is likely that you really want to look at Catalyst::Controller::REST,
42 which brings this class together with automatic Serialization of
43 requests and responses.
45 When you use this module, it adds the Catalyst::TraitFor::Request::REST
46 role to your request class.
50 This method overrides the default dispatch mechanism to the
51 re-dispatching mechanism described above.
54 You likely want to look at Catalyst::Controller::REST, which implements
55 a sensible set of defaults for a controller doing REST.
57 This class automatically adds the Catalyst::TraitFor::Request::REST role
58 to your request class. If you're writing a webapp which provides RESTful
59 responses and still needs to accomodate web browsers, you may prefer to
60 use Catalyst::TraitFor::Request::REST::ForBrowsers instead.
62 Catalyst::Action::Serialize, Catalyst::Action::Deserialize
65 Q: I'm getting a "415 Unsupported Media Type" error. What gives?!
66 A: Most likely, you haven't set Content-type equal to
67 "application/json", or one of the accepted return formats. You can
68 do this by setting it in your query accepted return formats. You can
69 do this by setting it in your query string thusly:
70 "?content-type=application%2Fjson (where %2F == / uri escaped)."
72 NOTE Apache will refuse %2F unless configured otherwise. Make sure
73 "AllowEncodedSlashes On" is in your httpd.conf file in order for
77 Adam Jacob <adam@stalecoffee.org>, with lots of help from mst and
80 Marchex, Inc. paid me while I developed this module.
81 (<http://www.marchex.com>)
84 Arthur Axel "fREW" Schmidt <frioux@gmail.com>
92 Daisuke Maki <daisuke@endeworks.jp>
94 J. Shirley <jshirley@gmail.com>
98 Tomas Doran (t0m) <bobtfish@bobtfish.net>
101 Copyright the above named AUTHOR and CONTRIBUTORS
104 You may distribute this code under the same terms as Perl itself.