Created
September 10, 2013 12:07
-
-
Save gideondsouza/6508454 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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