diff options
author | franck cuny <franck@lumberjaph.net> | 2010-03-19 00:26:54 +0100 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2010-03-19 00:26:54 +0100 |
commit | 7b5664b1bd92b7518d329fc07750f8680ecda4dc (patch) | |
tree | 65f3985e25309eeffcb8538a602f1c8416c6a89c /dancerREST.pm | |
parent | initial import (diff) | |
download | dancer-rest-7b5664b1bd92b7518d329fc07750f8680ecda4dc.tar.gz |
minor update
Diffstat (limited to '')
-rw-r--r-- | dancerREST.pm | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/dancerREST.pm b/dancerREST.pm index 7b0ed0f..90bb1ff 100644 --- a/dancerREST.pm +++ b/dancerREST.pm @@ -1,6 +1,5 @@ package dancerREST; use Dancer; -use Dancer::SharedData; my %users = (); @@ -21,7 +20,7 @@ get '/api/user/' => sub { # curl -H "Content-Type: application/json" http://localhost:5000/api/user/1 # => {"name":"foo"} get '/api/user/:id' => sub { - my $params = Dancer::SharedData->request->params; + my $params = request->params; if ( exists $users{ $params->{id} } ) { return $users{$params->{id}}; } @@ -34,7 +33,7 @@ get '/api/user/:id' => sub { # curl -H "Content-Type: application/json" -X POST http://localhost:5000/api/user/ -d '{"name":"foo","id":1}' # => {"name":"foo","id":"1"} post '/api/user/' => sub { - my $params = Dancer::SharedData->request->params; + my $params = request->params; if ( $params->{name} && $params->{id} ) { if ( exists $users{ $params->{id} } ) { return { error => "user already exists" }; @@ -48,10 +47,10 @@ post '/api/user/' => sub { }; # delete a user -# curl -H "Content-Type: application/json" -X DELETE http://localhost:5000/api/user/1 +# curl -H "Content-Type: application/json" -X DELETE http://localhost:5000/api/user/1 # {"deleted":1} del '/api/user/:id' => sub { - my $params = Dancer::SharedData->request->params; + my $params = request->params; if ( $params->{id} ) { if ( exists $users{ $params->{id} } ) { delete $users{ $params->{id} }; @@ -70,7 +69,7 @@ del '/api/user/:id' => sub { # or # curl -H "X-Requested-With: XMLHttpRequest" http://localhost:5000/user/1 get '/user/:id' => sub { - my $params = Dancer::SharedData->request->params; + my $params = request->params; my $user = $users{ $params->{id} }; my $result; if ( !$user ) { @@ -83,9 +82,9 @@ get '/user/:id' => sub { sub _render_user { my $result = shift; - my $request = Dancer::SharedData->request; + my $request = request; if ( $request->is_ajax ) { - return Dancer::Serializer->engine->serialize($result); + return $result; } else { template 'user.tt', $result; |