in reply to Re^2: json return value
in thread json return value
It's really not that difficult...
Server
use v5.14; use CGI (); use JSON::PP (); my $q = 'CGI'->new; my $json = 'JSON::PP'->new; my $input = $json->decode( $q->param('POSTDATA') ); my $a = $input->{a}; my $b = $input->{b}; my $c = $a + $b; print $q->header("application/json"); print $json->encode({ c => $c });
Client
use v5.14; use HTTP::Tiny (); use JSON::PP (); my $json = 'JSON::PP'->new; my $http = 'HTTP::Tiny'->new; my $url = 'http://buzzword.org.uk/2013/json-addition.cgi'; my $input = { a => 40, b => 2 }; my @request = ($url => { content => $json->encode($input) }); my $response = $http->post(@request); my $output = $json->decode($response->{content}); say $output->{c};
(All modules used above are part of Perl core as of 5.14+, but CGI is scheduled to leave core in a future version of Perl.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: json return value
by stenasc (Novice) on Jul 14, 2013 at 22:27 UTC | |
by tobyink (Canon) on Jul 15, 2013 at 05:45 UTC | |
by stenasc (Novice) on Jul 15, 2013 at 07:42 UTC | |
by Corion (Patriarch) on Jul 15, 2013 at 07:44 UTC | |
by stenasc (Novice) on Jul 15, 2013 at 20:44 UTC | |
by poj (Abbot) on Jul 16, 2013 at 07:27 UTC | |
by stenasc (Novice) on Jul 16, 2013 at 07:50 UTC | |
| |
by Anonymous Monk on Jul 16, 2013 at 08:23 UTC | |
by Anonymous Monk on Jul 14, 2013 at 23:44 UTC |