Skip to content

Instantly share code, notes, and snippets.

@gideondsouza
Created September 10, 2013 12:07
Show Gist options
  • Save gideondsouza/6508454 to your computer and use it in GitHub Desktop.
Save gideondsouza/6508454 to your computer and use it in GitHub Desktop.
package MyWebService;
use Dancer;
use Dancer::Plugin::REST;
#this line kicks in the plugin. So now whatever you return will be formatted and send back
prepare_serializer_for_format;
#this sets up a route that takes an id a dot and an extension
get '/user/:id.:format' => sub {
User->find(params->{id});#return some reference to a hash or array or what have you
};
# curl http://mywebservice/user/42.json
{ "id": 42, "name": "John Foo", email: "[email protected]"}
# curl http://mywebservice/user/42.yml
--
id: 42
name: "John Foo"
email: "[email protected]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment