Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

dancer::serializer(3pm) [debian man page]

Dancer::Serializer(3pm) 				User Contributed Perl Documentation				   Dancer::Serializer(3pm)

NAME
Dancer::Serializer - serializer wrapper for Dancer DESCRIPTION
This module is the wrapper that provides support for different serializers. USAGE
Configuration The serializer configuration variable tells Dancer which serializer to use to deserialize request and serialize response. You change it either in your config.yml file: serializer: "YAML" Or in the application code: # setting JSON as the default serializer set serializer => 'JSON'; In your routes you can access parameters just like any route. When in a route you return a Perl data structure, it will be serialized automatically to the respective serialized engine (for instance, "JSON"). For "PUT" and "POST" methods you can access the "request-"body> as a string, and you can unserialize it, if you really need. If your content type is recognized by the serializer, "request-"body> will be unserialized automatically, and it will be available as a standard parameter. For instance, if you call curl -X POST -H 'Content-Type: application/json -d "{'id':'bar'}" /foo your "foo" route can do something like: post "/foo" => { my $id = param('id'); # gets "bar" # ... } AUTHORS
This module has been written by Alexis Sukrieh and Franck Cuny. See the AUTHORS file that comes with this distribution for details. LICENSE
This module is free software and is released under the same terms as Perl itself. SEE ALSO
See Dancer for details about the complete framework. perl v5.14.2 2012-01-28 Dancer::Serializer(3pm)

Check Out this Related Man Page

Dancer::Plugin::REST(3pm)				User Contributed Perl Documentation				 Dancer::Plugin::REST(3pm)

NAME
Dancer::Plugin::REST - A plugin for writing RESTful apps with Dancer SYNOPSYS
package MyWebService; use Dancer; use Dancer::Plugin::REST; prepare_serializer_for_format; get '/user/:id.:format' => sub { User->find(params->{id}); }; # curl http://mywebservice/user/42.json { "id": 42, "name": "John Foo", email: "john.foo@example.com"} # curl http://mywebservice/user/42.yml -- id: 42 name: "John Foo" email: "john.foo@example.com" DESCRIPTION
This plugin helps you write a RESTful webservice with Dancer. KEYWORDS
prepare_serializer_for_format When this pragma is used, a before filter is set by the plugin to automatically change the serializer when a format is detected in the URI. That means that each route you define with a :format token will trigger a serializer definition, if the format is known. This lets you define all the REST actions you like as regular Dancer route handlers, without explicitly handling the outgoing data format. resource This keyword lets you declare a resource your application will handle. resource user => get => sub { # return user where id = params->{id} }, create => sub { # create a new user with params->{user} }, delete => sub { # delete user where id = params->{id} }, update => sub { # update user with params->{user} }; # this defines the following routes: # GET /user/:id # GET /user/:id.:format # POST /user # POST /user.:format # DELETE /user/:id # DELETE /user/:id.:format # PUT /user/:id # PUT /user/:id.:format helpers Some helpers are available. This helper will set an appropriate HTTP status for you. status_ok status_ok({users => {...}}); Set the HTTP status to 200 status_created status_created({users => {...}}); Set the HTTP status to 201 status_accepted status_accepted({users => {...}}); Set the HTTP status to 202 status_bad_request status_bad_request("user foo can't be found"); Set the HTTP status to 400. This function as for argument a scalar that will be used under the key error. status_not_found status_not_found("users doesn't exists"); Set the HTTP status to 404. This function as for argument a scalar that will be used under the key error. LICENCE
This module is released under the same terms as Perl itself. AUTHORS
This module has been written by Alexis Sukrieh "<sukria@sukria.net>" and Franck Cuny. SEE ALSO
Dancer <http://en.wikipedia.org/wiki/Representational_State_Transfer> perl v5.14.2 2011-11-01 Dancer::Plugin::REST(3pm)
Man Page