.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Catalyst::Action::Deserialize 3pm" .TH Catalyst::Action::Deserialize 3pm "2022-06-09" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Catalyst::Action::Deserialize \- Deserialize Data in a Request .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& package Foo::Controller::Bar; \& \& _\|_PACKAGE_\|_\->config( \& \*(Aqdefault\*(Aq => \*(Aqtext/x\-yaml\*(Aq, \& \*(Aqstash_key\*(Aq => \*(Aqrest\*(Aq, \& \*(Aqmap\*(Aq => { \& \*(Aqtext/x\-yaml\*(Aq => \*(AqYAML\*(Aq, \& \*(Aqtext/x\-data\-dumper\*(Aq => [ \*(AqData::Serializer\*(Aq, \*(AqData::Dumper\*(Aq ], \& }, \& ); \& \& sub begin :ActionClass(\*(AqDeserialize\*(Aq) {} .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This action will deserialize \s-1HTTP POST, PUT, OPTIONS\s0 and \s-1DELETE\s0 requests. It assumes that the body of the \s-1HTTP\s0 Request is a serialized object. The serializer is selected by introspecting the requests content-type header. .PP If you want deserialize any other \s-1HTTP\s0 method besides \s-1POST, PUT, OPTIONS\s0 and \s-1DELETE\s0 you can do this by setting the \&\f(CW\*(C`deserialize_http_methods\*(C'\fR list via \f(CW\*(C`action_args\*(C'\fR. Just modify the config in your controller and define a list of \s-1HTTP\s0 methods the deserialization should happen for: .PP .Vb 7 \& _\|_PACKAGE_\|_\->config( \& action_args => { \& \*(Aq*\*(Aq => { \& deserialize_http_methods => [qw(POST PUT OPTIONS DELETE GET)] \& } \& } \& ); .Ve .PP See also \*(L"action_args\*(R" in Catalyst::Controller. .PP The specifics of deserializing each content-type is implemented as a plugin to Catalyst::Action::Deserialize. You can see a list of currently implemented plugins in Catalyst::Controller::REST. .PP The results of your Deserializing will wind up in \f(CW$c\fR\->req\->data. This is done through the magic of Catalyst::Request::REST. .PP While it is common for this Action to be called globally as a \&\f(CW\*(C`begin\*(C'\fR method, there is nothing stopping you from using it on a single routine: .PP .Vb 1 \& sub foo :Local :Action(\*(AqDeserialize\*(Aq) {} .Ve .PP Will work just fine. .PP When you use this module, the request class will be changed to Catalyst::Request::REST. .SH "RFC 7231 Compliance Mode" .IX Header "RFC 7231 Compliance Mode" To maintain backwards compatibility with the module's original functionality, where it was assumed the deserialize and serialize content types are the same, an optional compliance mode can be enabled to break this assumption. .PP .Vb 10 \& _\|_PACKAGE_\|_\->config( \& \*(Aqcompliance_mode\*(Aq => 1, \& \*(Aqdefault\*(Aq => \*(Aqtext/x\-yaml\*(Aq, \& \*(Aqstash_key\*(Aq => \*(Aqrest\*(Aq, \& \*(Aqmap\*(Aq => { \& \*(Aqtext/x\-yaml\*(Aq => \*(AqYAML\*(Aq, \& \*(Aqtext/x\-data\-dumper\*(Aq => [ \*(AqData::Serializer\*(Aq, \*(AqData::Dumper\*(Aq ], \& }, \& \*(Aqdeserialize_default => \*(Aqapplication/json\*(Aq, \& \*(Aqdeserialize_map\*(Aq => { \& \*(Aqapplication/json\*(Aq => \*(AqJSON\*(Aq, \& }, \& ); .Ve .PP Three extra keys are added to the controller configuration. compliance_mode, a boolean to enable the mode. And a parallel set of content type mappings \&'deserialize_default' and 'deserialize_map' to mirror the default/map configuration keys. .PP The module will use the default/map keys when negotiating the serializing content type specified by the client in the Accept header. And will use the deserialize_default/deserialize_map in conjunction with the Content-Type header where the client is giving the content type being sent in the request. .SH "CUSTOM ERRORS" .IX Header "CUSTOM ERRORS" For building custom error responses when de-serialization fails, you can create an ActionRole (and use Catalyst::Controller::ActionRole to apply it to the \&\f(CW\*(C`begin\*(C'\fR action) which overrides \f(CW\*(C`unsupported_media_type\*(C'\fR and/or \f(CW\*(C`serialize_bad_request\*(C'\fR methods. .SH "SEE ALSO" .IX Header "SEE ALSO" You likely want to look at Catalyst::Controller::REST, which implements a sensible set of defaults for a controller doing \s-1REST.\s0 .PP Catalyst::Action::Serialize, Catalyst::Action::REST .SH "AUTHORS" .IX Header "AUTHORS" See Catalyst::Action::REST for authors. .SH "LICENSE" .IX Header "LICENSE" You may distribute this code under the same terms as Perl itself.