| 1 |
NAME |
| 2 |
|
| 3 |
Catalyst::Action::REST - Automated REST Method Dispatching |
| 4 |
|
| 5 |
SYNOPSIS |
| 6 |
|
| 7 |
sub foo :Local :ActionClass('REST') { |
| 8 |
... do setup for HTTP method specific handlers ... |
| 9 |
} |
| 10 |
|
| 11 |
sub foo_GET { |
| 12 |
... do something for GET requests ... |
| 13 |
} |
| 14 |
|
| 15 |
# alternatively use an Action |
| 16 |
sub foo_PUT : Action { |
| 17 |
... do something for PUT requests ... |
| 18 |
} |
| 19 |
|
| 20 |
DESCRIPTION |
| 21 |
|
| 22 |
This Action handles doing automatic method dispatching for REST |
| 23 |
requests. It takes a normal Catalyst action, and changes the dispatch |
| 24 |
to append an underscore and method name. First it will try dispatching |
| 25 |
to an action with the generated name, and failing that it will try to |
| 26 |
dispatch to a regular method. |
| 27 |
|
| 28 |
For example, in the synopsis above, calling GET on "/foo" would result |
| 29 |
in the foo_GET method being dispatched. |
| 30 |
|
| 31 |
If a method is requested that is not implemented, this action will |
| 32 |
return a status 405 (Method Not Found). It will populate the "Allow" |
| 33 |
header with the list of implemented request methods. You can override |
| 34 |
this behavior by implementing a custom 405 handler like so: |
| 35 |
|
| 36 |
sub foo_not_implemented { |
| 37 |
... handle not implemented methods ... |
| 38 |
} |
| 39 |
|
| 40 |
If you do not provide an _OPTIONS subroutine, we will automatically |
| 41 |
respond with a 200 OK. The "Allow" header will be populated with the |
| 42 |
list of implemented request methods. If you do not provide an _HEAD |
| 43 |
either, we will auto dispatch to the _GET one in case it exists. |
| 44 |
|
| 45 |
It is likely that you really want to look at |
| 46 |
Catalyst::Controller::REST, which brings this class together with |
| 47 |
automatic Serialization of requests and responses. |
| 48 |
|
| 49 |
When you use this module, it adds the Catalyst::TraitFor::Request::REST |
| 50 |
role to your request class. |
| 51 |
|
| 52 |
METHODS |
| 53 |
|
| 54 |
dispatch |
| 55 |
|
| 56 |
This method overrides the default dispatch mechanism to the |
| 57 |
re-dispatching mechanism described above. |
| 58 |
|
| 59 |
SEE ALSO |
| 60 |
|
| 61 |
You likely want to look at Catalyst::Controller::REST, which implements |
| 62 |
a sensible set of defaults for a controller doing REST. |
| 63 |
|
| 64 |
This class automatically adds the Catalyst::TraitFor::Request::REST |
| 65 |
role to your request class. If you're writing a web application which |
| 66 |
provides RESTful responses and still needs to accommodate web browsers, |
| 67 |
you may prefer to use Catalyst::TraitFor::Request::REST::ForBrowsers |
| 68 |
instead. |
| 69 |
|
| 70 |
Catalyst::Action::Serialize, Catalyst::Action::Deserialize |
| 71 |
|
| 72 |
TROUBLESHOOTING |
| 73 |
|
| 74 |
Q: I'm getting a "415 Unsupported Media Type" error. What gives?! |
| 75 |
|
| 76 |
A: Most likely, you haven't set Content-type equal to |
| 77 |
"application/json", or one of the accepted return formats. You can do |
| 78 |
this by setting it in your query accepted return formats. You can do |
| 79 |
this by setting it in your query string thusly: |
| 80 |
?content-type=application%2Fjson (where %2F == / uri escaped). |
| 81 |
|
| 82 |
NOTE Apache will refuse %2F unless configured otherwise. Make sure |
| 83 |
AllowEncodedSlashes On is in your httpd.conf file in order for this |
| 84 |
to run smoothly. |
| 85 |
|
| 86 |
AUTHOR |
| 87 |
|
| 88 |
Adam Jacob <[email protected]>, with lots of help from mst and |
| 89 |
jrockway |
| 90 |
|
| 91 |
Marchex, Inc. paid me while I developed this module. |
| 92 |
(http://www.marchex.com) |
| 93 |
|
| 94 |
CONTRIBUTORS |
| 95 |
|
| 96 |
Tomas Doran (t0m) <[email protected]> |
| 97 |
|
| 98 |
John Goulah |
| 99 |
|
| 100 |
Christopher Laco |
| 101 |
|
| 102 |
Daisuke Maki <[email protected]> |
| 103 |
|
| 104 |
Hans Dieter Pearcey |
| 105 |
|
| 106 |
Brian Phillips <[email protected]> |
| 107 |
|
| 108 |
Dave Rolsky <[email protected]> |
| 109 |
|
| 110 |
Luke Saunders |
| 111 |
|
| 112 |
Arthur Axel "fREW" Schmidt <[email protected]> |
| 113 |
|
| 114 |
J. Shirley <[email protected]> |
| 115 |
|
| 116 |
Gavin Henry <[email protected]> |
| 117 |
|
| 118 |
Gerv http://www.gerv.net/ |
| 119 |
|
| 120 |
Colin Newell <[email protected]> |
| 121 |
|
| 122 |
Wallace Reis <[email protected]> |
| 123 |
|
| 124 |
André Walker (andrewalker) <[email protected]> |
| 125 |
|
| 126 |
COPYRIGHT |
| 127 |
|
| 128 |
Copyright (c) 2006-2015 the above named AUTHOR and CONTRIBUTORS |
| 129 |
|
| 130 |
LICENSE |
| 131 |
|
| 132 |
You may distribute this code under the same terms as Perl itself. |
| 133 |
|