How to pass Named Arguments in Dancer URL
Hi Experts, Currently I am accessing the variables using "/method/:name/:id" I want to know how can I send named arguments like query string /method/name=:name/id=:id/ The above doesn't seems to be working, Am I doing anything wrong. Let me Know in case of any further informations required. Thanks Anand.
2015-09-16 12:16 GMT+03:00 Parthiban, Anandaraaj <anandaraj.parthiban@cgi.com>:
I want to know how can I send named arguments like query string /method/name=:name/id=:id/
Good old query-string approach does not suit to you? Like: /method?name=somename&id=1234 Wbr, -- Kõike hääd, Gunnar
But How do we pass that Let me Know in case of any further informations required. Thanks Anand. -----Original Message----- From: dancer-users [mailto:dancer-users-bounces@dancer.pm] On Behalf Of WK Sent: Wednesday, September 16, 2015 3:01 PM To: Perl Dancer users mailing list Subject: Re: [dancer-users] How to pass Named Arguments in Dancer URL 2015-09-16 12:16 GMT+03:00 Parthiban, Anandaraaj <anandaraj.parthiban@cgi.com>:
I want to know how can I send named arguments like query string /method/name=:name/id=:id/
Good old query-string approach does not suit to you? Like: /method?name=somename&id=1234 Wbr, -- Kõike hääd, Gunnar _______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
2015-09-16 12:39 GMT+03:00 Parthiban, Anandaraaj <anandaraj.parthiban@cgi.com>:
But How do we pass that
Let me Know in case of any further informations required.
get '/method' => sub { # you have two ways to access params from query string : # first, there is Dancer keyword `param` my $name = param('name'); # second, there is Dancer method `params` my $id = params->{ 'id' }; # do whatever you need here }; Wbr, -- Kõike hääd, Gunnar
Thanks Kõike hääd, But I can't get this going. My Sample Code: sub TEST { my $name = param('test'); my $ID = param('ID'); return {Message => "Welcome to Montoo Update Event $name $ID"}; } get '/method/Entity=:test&ID=:ID' => \&TEST; Let me Know in case of any further informations required. Thanks Anand. -----Original Message----- From: dancer-users [mailto:dancer-users-bounces@dancer.pm] On Behalf Of WK Sent: Wednesday, September 16, 2015 3:40 PM To: Perl Dancer users mailing list Subject: Re: [dancer-users] How to pass Named Arguments in Dancer URL 2015-09-16 12:39 GMT+03:00 Parthiban, Anandaraaj <anandaraj.parthiban@cgi.com<mailto:anandaraj.parthiban@cgi.com>>:
But How do we pass that
Let me Know in case of any further informations required.
get '/method' => sub { # you have two ways to access params from query string : # first, there is Dancer keyword `param` my $name = param('name'); # second, there is Dancer method `params` my $id = params->{ 'id' }; # do whatever you need here }; Wbr, -- Kõike hääd, Gunnar _______________________________________________ dancer-users mailing list dancer-users@dancer.pm<mailto:dancer-users@dancer.pm> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
2015-09-16 13:21 GMT+03:00 Parthiban, Anandaraaj <anandaraj.parthiban@cgi.com>:
get '/method/Entity=:test&ID=:ID' => \&TEST;
You overcomplicate your route-definition. Query string is not a part of route definition. You need only: get '/method' => \&TEST; And when you now query it like: http://localhost:3000/method?test=xyz&ID=123 It should work fine. If you really need URLs like http://localhost:3000/method/test=xyz/ID=123 you can buid your routes with regex, something like that (code not tested): get qr{/method/name=([\w]+)/ID=([\d]+)} => sub { my ($name, $id) = splat; }; Then you can use all the power of regexes for your URLs. Wbr, -- Kõike hääd, Gunnar
Hi Kõike hääd, Thank you so much for the help. Worked like charm. Let me Know in case of any further informations required. Thanks Anand. -----Original Message----- From: dancer-users [mailto:dancer-users-bounces@dancer.pm] On Behalf Of WK Sent: Wednesday, September 16, 2015 4:20 PM To: Perl Dancer users mailing list Subject: Re: [dancer-users] How to pass Named Arguments in Dancer URL 2015-09-16 13:21 GMT+03:00 Parthiban, Anandaraaj <anandaraj.parthiban@cgi.com>:
get '/method/Entity=:test&ID=:ID' => \&TEST;
You overcomplicate your route-definition. Query string is not a part of route definition. You need only: get '/method' => \&TEST; And when you now query it like: http://localhost:3000/method?test=xyz&ID=123 It should work fine. If you really need URLs like http://localhost:3000/method/test=xyz/ID=123 you can buid your routes with regex, something like that (code not tested): get qr{/method/name=([\w]+)/ID=([\d]+)} => sub { my ($name, $id) = splat; }; Then you can use all the power of regexes for your URLs. Wbr, -- Kõike hääd, Gunnar _______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
participants (2)
-
Parthiban, Anandaraaj -
WK