We would like to create an API using REST and EMBPERL. Did you come
up with a working solution to implement REST with embperl?
Yes, for my little use everything is working nicely.
I attach the tiny project. It's quite raw and in french. If you need any
explanation, feel free to ask.
Best regards,
[- Execute('*'); -]
[-
use Data::Dumper;
use Apache2::Request;
use Apache2::RequestIO;
use JSON;
my $buffer;
$req_rec->read($buffer,9999);
my $pp = decode_json($buffer);
my %p = %$pp;
my @messages;
$escmode=0;
$req=shift;
Execute($ENV{DOCUMENT_ROOT}.'/basedb.epl');
# Actions
if (! defined $p{action}) {
push(@messages,'Il manque le paramètre "action"');
}
if ($p{action} ne 'chpasswd') {
push(@messages,'action inconnue : "'.$p{action}.'" (actions valides : chpasswd)');
}
# uid
if (! defined $p{uid}) {
push(@messages,'Il manque le paramètre "uid"');
}
if (scalar(@messages)==0) {
print OUT encode_json( { status => 'OK'} );
if ($req->{dbh}->do("INSERT INTO actionsqueue (actiontype,param1) VALUES(\$1,\$2)",{},($p{action},$p{uid}))) {
warn("$0: INSERT ok");
}
else {
warn "$0: ".$req->{dbh}->errstr;
}
}
else {
print OUT encode_json( { status => 'ERROR', messages => \@messages} );
print OUT "\n";
while ( ($k,$v) = each(%p) ) {
print OUT "$k: $v\n";
}
}
-]
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscr...@perl.apache.org
For additional commands, e-mail: embperl-h...@perl.apache.org