1Catalyst::Action::DeserUisaelrizCeo(n3t)ributed Perl DocCuamteanltyastti:o:nAction::Deserialize(3)
2
3
4

NAME

6       Catalyst::Action::Deserialize - Deserialize Data in a Request
7

SYNOPSIS

9           package Foo::Controller::Bar;
10
11           __PACKAGE__->config(
12               'default'   => 'text/x-yaml',
13               'stash_key' => 'rest',
14               'map'       => {
15                   'text/x-yaml'        => 'YAML',
16                   'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ],
17               },
18           );
19
20           sub begin :ActionClass('Deserialize') {}
21

DESCRIPTION

23       This action will deserialize HTTP POST, PUT, OPTIONS and DELETE
24       requests.  It assumes that the body of the HTTP Request is a serialized
25       object.  The serializer is selected by introspecting the requests
26       content-type header.
27
28       If you want deserialize any other HTTP method besides POST, PUT,
29       OPTIONS and DELETE you can do this by setting the
30       "deserialize_http_methods" list via "action_args".  Just modify the
31       config in your controller and define a list of HTTP methods the
32       deserialization should happen for:
33
34           __PACKAGE__->config(
35               action_args => {
36                   '*' => {
37                       deserialize_http_methods => [qw(POST PUT OPTIONS DELETE GET)]
38                   }
39               }
40           );
41
42       See also "action_args" in Catalyst::Controller.
43
44       The specifics of deserializing each content-type is implemented as a
45       plugin to Catalyst::Action::Deserialize.  You can see a list of
46       currently implemented plugins in Catalyst::Controller::REST.
47
48       The results of your Deserializing will wind up in $c->req->data.  This
49       is done through the magic of Catalyst::Request::REST.
50
51       While it is common for this Action to be called globally as a "begin"
52       method, there is nothing stopping you from using it on a single
53       routine:
54
55          sub foo :Local :Action('Deserialize') {}
56
57       Will work just fine.
58
59       When you use this module, the request class will be changed to
60       Catalyst::Request::REST.
61

RFC 7231 Compliance Mode

63       To maintain backwards compatibility with the module's original
64       functionality, where it was assumed the deserialize and serialize
65       content types are the same, an optional compliance mode can be enabled
66       to break this assumption.
67
68           __PACKAGE__->config(
69               'compliance_mode'    => 1,
70               'default'            => 'text/x-yaml',
71               'stash_key'          => 'rest',
72               'map'                => {
73                   'text/x-yaml'        => 'YAML',
74                   'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ],
75               },
76               'deserialize_default => 'application/json',
77               'deserialize_map'    => {
78                   'application/json'   => 'JSON',
79               },
80           );
81
82       Three extra keys are added to the controller configuration.
83       compliance_mode, a boolean to enable the mode. And a parallel set of
84       content type mappings 'deserialize_default' and 'deserialize_map' to
85       mirror the default/map configuration keys.
86
87       The module will use the default/map keys when negotiating the
88       serializing content type specified by the client in the Accept header.
89       And will use the deserialize_default/deserialize_map in conjunction
90       with the Content-Type header where the client is giving the content
91       type being sent in the request.
92

CUSTOM ERRORS

94       For building custom error responses when de-serialization fails, you
95       can create an ActionRole (and use Catalyst::Controller::ActionRole to
96       apply it to the "begin" action) which overrides
97       "unsupported_media_type" and/or "serialize_bad_request" methods.
98

SEE ALSO

100       You likely want to look at Catalyst::Controller::REST, which implements
101       a sensible set of defaults for a controller doing REST.
102
103       Catalyst::Action::Serialize, Catalyst::Action::REST
104

AUTHORS

106       See Catalyst::Action::REST for authors.
107

LICENSE

109       You may distribute this code under the same terms as Perl itself.
110
111
112
113perl v5.36.0                      2023-01-20  Catalyst::Action::Deserialize(3)
Impressum