Mailing List Archive

Question concerning REST
Hello,

I am trying to implement a simple REST/JSON server in embedded perl but
I don't understand how I can retrieve the data sent to me.

I test with this command :

curl -i -X GET -d '{"name":"john"}' http://omico.miaou/rest/notifent.html


And the following code shows nothing (apart from the %ENV stuff) :

[.-
use Data::Dumper;

$req = shift;

while ( ($k,$v) = each(%fdat) ) {
warn "$0:FDAT $k : ".Dumper($v);
}

while ( ($k,$v) = each(%udat) ) {
warn "$0:UDAT: $k : ".Dumper($v);
}

while ( ($k,$v) = each(%ENV) ) {
warn "$0:ENV: $k : ".Dumper($v);
}

foreach $k (@param) {
warn "$0:param: $k ";
}

-]

Thanks for your help,

JC

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Question concerning REST [ In reply to ]
Hello,

I am trying to implement a simple REST/JSON server in embedded perl but
I don't understand how I can retrieve the data sent to me.

I test with this command :

curl -i -X GET -d '{"name":"john"}' http://omico.miaou/rest/notifent.html


And the following code shows nothing (apart from the %ENV stuff) :

[.-
use Data::Dumper;

$req = shift;

while ( ($k,$v) = each(%fdat) ) {
warn "$0:FDAT $k : ".Dumper($v);
}

while ( ($k,$v) = each(%udat) ) {
warn "$0:UDAT: $k : ".Dumper($v);
}

while ( ($k,$v) = each(%ENV) ) {
warn "$0:ENV: $k : ".Dumper($v);
}

foreach $k (@param) {
warn "$0:param: $k ";
}

-]

Thanks for your help,

JC

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Question concerning REST [ In reply to ]
Hello,

I am trying to implement a simple REST/JSON server in embedded perl but
I don't understand how I can retrieve the data sent to me.

I test with this command :

curl -i -X GET -d '{"name":"john"}' http://omico.miaou/rest/notifent.html


And the following code shows nothing (apart from the %ENV stuff) :

[.-
use Data::Dumper;

$req = shift;

while ( ($k,$v) = each(%fdat) ) {
warn "$0:FDAT $k : ".Dumper($v);
}

while ( ($k,$v) = each(%udat) ) {
warn "$0:UDAT: $k : ".Dumper($v);
}

while ( ($k,$v) = each(%ENV) ) {
warn "$0:ENV: $k : ".Dumper($v);
}

foreach $k (@param) {
warn "$0:param: $k ";
}

-]

Thanks for your help,

JC

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: Question concerning REST [ In reply to ]
Embperl internally uses CGI.pm to process "data sent to you".
Therefore it can't handle mime types other than multipart/form-data or
application/x-www-form-urlencoded.
I'm even not sure if it can handle HTTP methods other than GET and POST.

2015-08-24 19:05 GMT+02:00 Jean-Christophe Boggio <embperl@thefreecat.org>:

>
> Hello,
>
> I am trying to implement a simple REST/JSON server in embedded perl but I
> don't understand how I can retrieve the data sent to me.
>
> I test with this command :
>
> curl -i -X GET -d '{"name":"john"}' http://omico.miaou/rest/notifent.html
>
>
> And the following code shows nothing (apart from the %ENV stuff) :
>
> [.-
> use Data::Dumper;
>
> $req = shift;
>
> while ( ($k,$v) = each(%fdat) ) {
> warn "$0:FDAT $k : ".Dumper($v);
> }
>
> while ( ($k,$v) = each(%udat) ) {
> warn "$0:UDAT: $k : ".Dumper($v);
> }
>
> while ( ($k,$v) = each(%ENV) ) {
> warn "$0:ENV: $k : ".Dumper($v);
> }
>
> foreach $k (@param) {
> warn "$0:param: $k ";
> }
>
> -]
>
> Thanks for your help,
>
> JC
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org
>
>


--
--
mit freundlichem Gruß,

Frank Wesemann
Fotofinder GmbH USt-IdNr. DE812854514
Software Entwicklung Web: http://www.fotofinder.com/
Potsdamer Str. 96 Tel: +49 30 25 79 28 90
10785 Berlin Fax: +49 30 25 79 28 999

Sitz: Berlin
Amtsgericht Berlin Charlottenburg (HRB 73099)
Geschäftsführer: Ali Paczensky
Re: Question concerning REST [ In reply to ]
Le 24/08/2015 19:57, Jim Howard a écrit :
> Darn. My only other bit of advice was "Are you sure Embperl is best for
> this?"

No, I'm not sure it's "the best". But I'm sure it's possible (see below).

> My company maintains a large Embperl app, but we use other tools for
> REST/JSON (one of the reasons we are moving away from Embperl).

My application is rather large and I only needed to create a small
webservice so switching to another language just to write 20 lines of
code was bugging me.


Okay, so solution that works for me :

1. a) You must disable Embperl's form data processing by using
optDisableFormData. I did this in :

<Location /rest>
EMBPERL_OPTIONS 256
</Location>

1. b) For some mysterious reason, doing this (and it does the same if I
rather use a <Directory> directive), the EMBPERL_OBJECT_BASE that I set
for the whole virtualhost to "base.epl" is lost and I *MUST* use
"_base.epl". Forcing it in the <Location>/<Directory> does not work. So
I did a symbolic link :

ln -s base.epl _base.epl

2. Then, in order to read the POSTDATA, the only way I found was to dig
in Apache2::Request. Here is my code. It works. At least for the very
small use I have.

First install the module :

sudo apt-get install libapache2-request-perl

[.-
use Apache2::Request;
use Apache2::RequestIO;

my $buffer;
$req_rec->read($buffer,9999);
warn "buffer::$buffer";
-]

I call it like this :

curl -i -X POST -d '{"name":"toto"}' http://omico.miaou/rest/notifent.html

And the logs say :

[Thu Aug 27 15:32:48 2015] [warn] [19141]ERR: 32: Warning in Perl
code: buffer::{"name":"toto"} at /.../omico/rest/notifent.html line 10.


Oh, and by the way, GET, PUT and DELETE also work.

Hope this helps.

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: Question concerning REST [ In reply to ]
Hello.

We would like to create an API using REST and EMBPERL.

Did you come up with a working solution to implement REST with embperl?

Thank You,

~Donavon


On 8/27/2015 6:40 AM, Jean-Christophe Boggio wrote:
> Le 24/08/2015 19:57, Jim Howard a écrit :
>> Darn. My only other bit of advice was "Are you sure Embperl is best for
>> this?"
>
> No, I'm not sure it's "the best". But I'm sure it's possible (see below).
>
>> My company maintains a large Embperl app, but we use other tools for
>> REST/JSON (one of the reasons we are moving away from Embperl).
>
> My application is rather large and I only needed to create a small
> webservice so switching to another language just to write 20 lines of
> code was bugging me.
>
>
> Okay, so solution that works for me :
>
> 1. a) You must disable Embperl's form data processing by using
> optDisableFormData. I did this in :
>
> <Location /rest>
> EMBPERL_OPTIONS 256
> </Location>
>
> 1. b) For some mysterious reason, doing this (and it does the same if
> I rather use a <Directory> directive), the EMBPERL_OBJECT_BASE that I
> set for the whole virtualhost to "base.epl" is lost and I *MUST* use
> "_base.epl". Forcing it in the <Location>/<Directory> does not work.
> So I did a symbolic link :
>
> ln -s base.epl _base.epl
>
> 2. Then, in order to read the POSTDATA, the only way I found was to
> dig in Apache2::Request. Here is my code. It works. At least for the
> very small use I have.
>
> First install the module :
>
> sudo apt-get install libapache2-request-perl
>
> [.-
> use Apache2::Request;
> use Apache2::RequestIO;
>
> my $buffer;
> $req_rec->read($buffer,9999);
> warn "buffer::$buffer";
> -]
>
> I call it like this :
>
> curl -i -X POST -d '{"name":"toto"}'
> http://omico.miaou/rest/notifent.html
>
> And the logs say :
>
> [Thu Aug 27 15:32:48 2015] [warn] [19141]ERR: 32: Warning in Perl
> code: buffer::{"name":"toto"} at /.../omico/rest/notifent.html line 10.
>
>
> Oh, and by the way, GET, PUT and DELETE also work.
>
> Hope this helps.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org